import { getSDKConfig } from "config";

import ProfileService, {
  InstagramUserInfo,
  TikTokListVideosResponse,
  TikTokUserInfo,
} from "@komi-app/profiles-sdk";
import { Response } from "redux/Common/types";

export default class ShortVideoService {
  private profileId = "";
  private profileService: ProfileService;

  constructor() {
    this.profileService = new ProfileService(getSDKConfig("profiles"));
  }

  init(profileId: string) {
    this.profileId = profileId;
    this.profileService.init(profileId);
  }

  resolveTikTokURL = async (url: string): Promise<Response<string>> => {
    const out = await this.profileService.resolveTikTokURL(url);

    return { ok: true, response: out };
  };

  connectTikTokOAuth = async (): Promise<string> => {
    return this.profileService.connectTikTokOAuth();
  };

  getTikTokAccounts = async (): Promise<Response<TikTokUserInfo[]>> => {
    const out = await this.profileService.getTikTokAccounts();
    return { ok: true, response: out };
  };

  connectInstagramOAuth = async (): Promise<string> => {
    return this.profileService.connectInstagramOAuth();
  };

  getInstagramAccounts = async (): Promise<Response<InstagramUserInfo[]>> => {
    const out = await this.profileService.getInstagramAccounts();
    return { ok: true, response: out };
  };

  getTikTokVideos = async (
    accountId: string,
    cursor?: string
  ): Promise<Response<TikTokListVideosResponse>> => {
    const out = await this.profileService.getTikTokVideos(accountId, cursor);
    return { ok: true, response: out };
  };

  disconnectTikTokAccount = async (
    accountId: string
  ): Promise<Response<void>> => {
    await this.profileService.disconnectTikTokAccount(accountId);
    return { ok: true, response: undefined };
  };

  disconnectInstagramAccount = async (
    accountId: string
  ): Promise<Response<void>> => {
    await this.profileService.disconnectInstagramAccount(accountId);
    return { ok: true, response: undefined };
  };
}
