import { InviteData, ParticipantInfo } from '@/pages/rtc/data'
import { RtcType } from '@/constants/action'
import useUserStore from '@/store/modules/user'
import useConversationStore from '@/store/modules/conversation'
import { v4 as uuidV4 } from 'uuid'
import { SessionType } from 'open-im-sdk-wasm'
import emitter from '@/utils/events'

export const useInviteRtc = () => {
  const userStore = useUserStore()
  const conversationStore = useConversationStore()

  const inviteRtc = async (type: RtcType, groupID: string, userIDList: string[]) => {
    const isGroup = groupID !== ''
    const mediaType = type === RtcType.VoiceCall ? 'audio' : 'video'

    emitter.emit('OPEN_RTC_MODAL', {
      invitation: {
        inviterUserID: userStore.selfInfo.userID,
        inviteeUserIDList: userIDList,
        groupID,
        // roomID: uuidV4(),
        roomID: `room-${userStore.selfInfo.userID}`,
        timeout: 60,
        mediaType,
        sessionType: isGroup ? SessionType.WorkingGroup : SessionType.Single,
        platformID: 5,
      },
      participant: {
        userInfo: {
          nickname: conversationStore.currentConversation.showName,
          userID: conversationStore.currentConversation.userID,
          faceURL: conversationStore.currentConversation.faceURL,
          ex: '',
        },
      },
    })
  }

  return {
    inviteRtc,
  }
}
