import { AccessToken2, ServiceChat } from './AccessToken2';

export class ChatTokenBuilder {
  /**
   * Build the Chat user token.
   * @param appId - The App ID issued to you by Agora.
   * @param appCertificate - Certificate of the application that you registered in the Agora Dashboard.
   * @param userUuid - The user's id, must be unique.
   * @param expire - represented by the number of seconds elapsed since now.
   * @returns The Chat User token.
   */
  public static buildUserToken(appId: string, appCertificate: string, userUuid: string, expire: number): string {
    const token = new AccessToken2(appId, appCertificate, undefined, expire);
    const serviceChat = new ServiceChat(userUuid);
    serviceChat.add_privilege(ServiceChat.kPrivilegeUser, expire);
    token.add_service(serviceChat);
    return token.build();
  }

  /**
   * Build the Chat App token.
   * @param appId - The App ID issued to you by Agora.
   * @param appCertificate - Certificate of the application that you registered in the Agora Dashboard.
   * @param expire - represented by the number of seconds elapsed since now.
   * @returns The Chat App token.
   */
  public static buildAppToken(appId: string, appCertificate: string, expire: number): string {
    const token = new AccessToken2(appId, appCertificate, undefined, expire);
    const serviceChat = new ServiceChat();
    serviceChat.add_privilege(ServiceChat.kPrivilegeApp, expire);
    token.add_service(serviceChat);
    return token.build();
  }
}
