import PCastApi, { ApplicationCredentials, Channel } from "@techniker-me/pcast-api";

class PCastApiService {
    private static _instance: PCastApiService = new PCastApiService();
    private _pcastApi: PCastApi | null = null;
    
    public static getInstance(): PCastApiService {
        return PCastApiService._instance;
    }

    public async initialize(pcastUri: string, applicationCredentials: ApplicationCredentials): Promise<void> {
        console.log('initialize', pcastUri, applicationCredentials);
        this._pcastApi = PCastApi.create(pcastUri, applicationCredentials);
    }

    public get pcastApi(): PCastApi | null {
        return this._pcastApi;
    }

    public async fetchChannelsList(): Promise<Channel[]> {
        return this._pcastApi?.channels.list() || [];
    }
}

export default PCastApiService.getInstance();