package com.module.backstage.activity.setting

import android.util.Log
import com.module.pay.service.HomeApiService
import com.quyunshuo.androidbaseframemvvm.base.mvvm.m.BaseRepository
import com.quyunshuo.androidbaseframemvvm.common.constant.Heartbeat
import com.quyunshuo.androidbaseframemvvm.common.util.AppTypeManger
import kotlinx.coroutines.delay
import javax.inject.Inject

/**
 * 首页M层
 *
 * @author Qu Yunshuo
 * @since 5/25/21 5:42 PM
 */
class SettingRepository @Inject constructor() : BaseRepository() {
    private val TAG = "SettingRepository"

    @Inject
    lateinit var mApi: HomeApiService

    /**
     * 模拟获取数据
     */
    suspend fun getData() = request<String> {
        delay(1000L)
        emit("Hello Hilt")
    }

    /**
     * 初始化设备
     */
    suspend fun initDev(text: String?) = request<String> {
        var params = HashMap<String, String>()
        Log.d(TAG, "initDev2: " + Heartbeat.deviceId)
        Log.d(TAG, "initDev2: " + text)
        Log.d(TAG, "initDev2: " + Heartbeat.clientId)
        params["clientId"] = Heartbeat.deviceId!!
        params["managerId"] = text!!
        params["gtClientId"] = Heartbeat.clientId!!
        params["equimentType"] = Heartbeat.equimentType
        Log.d(TAG, "initDev1: " + params)
        mApi.initDev(params).run {
            emit(this)
        }
    }

    /**
     * 检查更新
     */
    suspend fun apkinfo() = request<String> {
        var params = HashMap<String, String>()
        if (AppTypeManger.getInstance().appChina) {
            params["model"] = Heartbeat.equimentType + "ch"
        } else {
            params["model"] = Heartbeat.equimentType + "en"
        }

        mApi.apkinfo(params).run {
            emit(this)
        }
    }


}