package com.adealink.weparty.module.playmate.event

import com.adealink.frame.log.Log
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.module.playmate.data.NotifyPlaymateWelcomeReq
import com.adealink.weparty.module.playmate.data.TAG_PLAYMATE_EVENT
import com.adealink.weparty.module.playmate.datasource.PlaymateHttpService
import kotlinx.coroutines.launch

class NotifyPlaymateWelcomeEvent() : BaseStatEvent("playmate") {

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

    val uid = Param(CommonEventKey.UID)
    override fun send() {
        launch {
            val uid = uid.value as? String ?: return@launch
            Log.d(TAG_PLAYMATE_EVENT, "report notify playmate welcome, uid:${uid}")
            playmateHttpService.notifyPlaymateWelcome(NotifyPlaymateWelcomeReq(uid))
        }
    }

    override fun toString(): String {
        return "NotifyPlaymateWelcomeEvent(uid:${uid})"
    }
}