import LibGenerateTestUserSig from './lib-generate-test-usersig-es.min.js'

import useAuthUser from '@/composables/useAuthUser'

/**
 * Expiration time for the signature, it is recommended not to set it too short.
 * Time unit: seconds
 * Default time: 7 x 24 x 60 x 60 = 604800 = 7 days
 */
const EXPIRETIME = 604800

export function genTestUserSig(userID) {
  const { tencentUserSig } = useAuthUser()
  const SDKAppID = tencentUserSig.value.sdkappID
  const SDKSECRETKEY = tencentUserSig.value.secretKey
  console.log('SDKAppID===============', SDKAppID)

  const generator = new LibGenerateTestUserSig(
    SDKAppID,
    SDKSECRETKEY,
    EXPIRETIME
  )
  const userSig = generator.genTestUserSig(userID)
  const userName = userID || `user_${Math.ceil(Math.random() * 10)}`

  return {
    SDKAppID,
    userSig,
    userName
  }
}
