package com.adealink.weparty.room.stat

import com.adealink.frame.log.Log
import com.adealink.frame.room.data.TAG_ROOM
import com.adealink.frame.statistics.BaseStatEvent
import com.adealink.frame.statistics.CommonEventKey
import com.adealink.frame.statistics.CommonEventValue
import com.adealink.frame.statistics.IEventValue
import com.adealink.weparty.App
import com.adealink.weparty.room.data.ReportRoomAvailableReq
import com.adealink.weparty.room.datasource.remote.RoomHttpService
import kotlinx.coroutines.launch

class RoomUnavailableEvent : BaseStatEvent("") {

    override val action: IEventValue = CommonEventValue.Action.EMPTY
    private val roomHttpService by lazy {
        App.instance.networkService.getHttpService(RoomHttpService::class.java)
    }

    val roomId = Param(CommonEventKey.ROOM_ID)
    val supplier = Param("supplier")
    val errorCode = Param("errorCode")
    val errorReason = Param("errorReason")
    override fun send() {
        launch {
            val roomId = roomId.value as? String ?: return@launch

            val errorCode = errorCode.value as? String
            val errorReason = errorReason.value as? String

            Log.d(TAG_ROOM, "report room unavailable, roomId:${roomId}")
            roomHttpService.reportRoomUnavailable(
                ReportRoomAvailableReq(
                    roomId,
                    errorCode = errorCode ?: "",
                    errorReason = errorReason ?: ""
                )
            )
        }
    }

    override fun toString(): String {
        return "UserPushSendMessageEvent(roomId:${roomId})"
    }

}