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

export class RtmTokenBuilder {
  /**
   * Build the RTM 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 userId - The user's account, max length is 64 Bytes.
   * @param expire - represented by the number of seconds elapsed since now.
   * @returns The RTM token.
   */
  public static buildToken(appId: string, appCertificate: string, userId: string, expire: number): string {
    const token = new AccessToken2(appId, appCertificate, undefined, expire);

    const serviceRtm = new ServiceRtm(userId);
    serviceRtm.add_privilege(ServiceRtm.kPrivilegeLogin, expire);
    token.add_service(serviceRtm);

    return token.build();
  }
}
