import {ApplicationCredentials, Channels, PCastApi, Reporting, Streams} from '@techniker-me/pcast-api';

export default class PCastApiService {
  private static _instance: PCastApi;

  public static initialize(pcastUri: string, applciationCredentials: ApplicationCredentials) {
    console.log(`${new Date().toISOString()} [PCastApiService] initialize pcastUri [%o] applciation [%o]`, pcastUri, applciationCredentials);
    PCastApiService._instance = PCastApi.create(pcastUri, applciationCredentials);
  }

  public static getInstance(): PCastApiService {
    if (!PCastApiService._instance) {
      throw new Error('PCastApiService has not been initialized');
    }

    return PCastApiService._instance;
  }

  static get channels(): Channels {
    if (!PCastApiService._instance) {
      throw new Error('PCastApiService has not been initialized');
    }

    return PCastApiService._instance.channels;
  }

  static get streams(): Streams {
    if (!PCastApiService._instance) {
      throw new Error('PCastApiService has not been initialized');
    }

    return PCastApiService._instance.streams;
  }

  static get reporting(): Reporting {
    if (!PCastApiService._instance) {
      throw new Error('PCastApiService has not been initialized');
    }

    return PCastApiService._instance.reporting;
  }
}
