package com.rc.httpcore.client

import com.rc.httpcore.HttpClient
import com.rc.httpcore.apk.AppInfo
import com.rc.httpcore.apk.ProcessedBean
import com.rc.httpcore.bean.*
import com.rc.httpcore.vo.request.*
import com.rc.httpcore.vo.response.*
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.schedulers.Schedulers
import java.io.File

object ApiRepository {

    private val mClientFactory by lazy { HttpClient.createClientFactory() }

    /**
     * 查询LOGO配置列表
     */
    fun queryLogoConfInfo(): Observable<ConfLogo> {
        return mClientFactory.createLabClient()
            .queryLogoConfInfo()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    /**
     * 查询APK版本
     *
     * @param id 设备唯一编码
     */
//    fun apkVersion(id: String): Observable<ApkInfoResp> {
//        return mClientFactory.createLabClient()
//            .apkVersion(id)
//            .subscribeOn(Schedulers.io())
//            .observeOn(AndroidSchedulers.mainThread())
//    }

//    fun apkVersion(deviceNum: String, type: Int, version: Double): Observable<AppUpDateBean> {
//        return mClientFactory.createLabClient()
//            .apkVersion(deviceNum, type, version)
//            .subscribeOn(Schedulers.io())
//            .observeOn(AndroidSchedulers.mainThread())
//    }

    fun getCheck(deviceNum: String, type: String, version: Double): Observable<AppInfo> {
        return mClientFactory.createLabClient()
            .getCheck(deviceNum, type, version)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun cardNum(cardNum: String): Observable<UserData> {
        return mClientFactory.createLabClient()
            .cardNum(cardNum)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun userCardValidation(userId: String, subId: String): Observable<UserValidationBean> {
        return mClientFactory.createLabClient()
            .userCardValidation(userId, subId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun searchChemica(
        searchChemica: String,
        chemicalLevel: String?
    ): Observable<List<ChemicalSearchBean>> {
        return mClientFactory.createLabClient()
            .searchChemica(searchChemica, chemicalLevel)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun getOptions(typs: String): Observable<List<ChemicalTypeBean>> {
        return mClientFactory.createLabClient()
            .getOptions(typs)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun searchProducer(): Observable<List<SearchBean>> {
        return mClientFactory.createLabClient()
            .searchProducer()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun searchSpec(specNum: String): Observable<SearchSpecBean> {
        return mClientFactory.createLabClient()
            .searchSpec(specNum)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun getSelects(searchValue: String): Observable<List<BelongingPersonBean>> {
        return mClientFactory.createLabClient()
            .getSelects(searchValue)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun getTopicList(userId: String): Observable<List<TopicDataBean>> {
        return mClientFactory.createLabClient()
            .getTopicList(userId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun getCabinetList(subId: String): Observable<List<RuleBean>> {
        return mClientFactory.createLabClient()
            .getCabinetList(subId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun getScanCode(macId: String, code: String, subId: String): Observable<UserData> {
        return mClientFactory.createLabClient()
            .getScanCode(macId, code, subId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun certitude(model: ChemicalABean): Observable<ChemicalABean> {
        return mClientFactory.createLabClient()
            .certitude(model)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun certitude(model: HxpChemicalVo): Observable<HxpChemicalVo> {
        return mClientFactory.createLabClient()
            .certitude(model)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun getRelList(subjectId: String): Observable<ChemicalInfoBean> {
        return mClientFactory.createLabClient()
            .getRelList(subjectId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun getUserIds(subId: String): Observable<List<String>> {
        return mClientFactory.createLabClient()
            .getUserIds(subId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun getCabinetBySubId(subId: String): Observable<List<RuleBean>> {
        return mClientFactory.createLabClient()
            .getCabinetBySubId(subId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun stockWaitAdd(model: StockModeBean): Observable<Boolean> {
        return mClientFactory.createLabClient()
            .stockWaitAdd(model)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun addStockCheck(model: StockModel): Observable<Boolean> {
        return mClientFactory.createLabClient()
            .addStockCheck(model)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun getStockWaitDetails(waitId: String): Observable<UnifiedVerBean> {
        return mClientFactory.createLabClient()
            .getStockWaitDetails(waitId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun waitList(mutableMap: Map<String, Any>): Observable<PageHxpStockBean> {
        return mClientFactory.createLabClient()
            .waitList(mutableMap)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun getStockList(mutableMap: Map<String, Any>): Observable<HxpStockWaitModeBean> {
        return mClientFactory.createLabClient()
            .getStockList(mutableMap)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun getByRfid(rfidCode: String): Observable<UseBean> {
        return mClientFactory.createLabClient()
            .getByRfid(rfidCode)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun indexDetailbyRfid(rfidCode: String): Observable<UseNoBean> {
        return mClientFactory.createLabClient()
            .indexDetailbyRfid(rfidCode)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun getStockDetailsByCode(rfidCode: String): Observable<UseNoTwoBean> {
        return mClientFactory.createLabClient()
            .getStockDetailsByCode(rfidCode)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun addUseRecord(model: UsePostDataBean): Observable<String> {
        return mClientFactory.createLabClient()
            .addUseRecord(model)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun useList(mutableMap: Map<String, String>): Observable<ReturningChemicalsBean> {
        return mClientFactory.createLabClient()
            .useList(mutableMap)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    //更换rfid
    fun updateRfid(ids: String, rfidCode: String): Observable<String> {
        return mClientFactory.createLabClient()
            .updateRfid(ids, rfidCode)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun backDetail(rfidCode: String, subId: String): Observable<ReturnDetailsBean> {
        return mClientFactory.createLabClient()
            .backDetail(rfidCode,subId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun chemicalSearchBean(rfidCode: String, subId: String): Observable<ChemicalSearchBean> {
        return mClientFactory.createLabClient()
            .chemicalSearchBean(rfidCode, subId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }


    fun discardDetail(rfidCode: String): Observable<ReturnDetailsBean> {
        return mClientFactory.createLabClient()
            .discardDetail(rfidCode)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun giveBack(model: GiveBackBean): Observable<Boolean> {
        return mClientFactory.createLabClient()
            .giveBack(model)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun returnGiveBack(model: GiveBackBean): Observable<ReturnGiveBackBean> {
        return mClientFactory.createLabClient()
            .returnGiveBack(model)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun stockDetailsList(mutableMap: Map<String, String>): Observable<WasteChemicalsBean> {
        return mClientFactory.createLabClient()
            .stockDetailsList(mutableMap)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun getCabinetLock(doorId: String): Observable<List<LockVoListBean>> {
        return mClientFactory.createLabClient()
            .getCabinetLock(doorId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun indexStockList(mutableMap: Map<String, String>): Observable<HxpStockWaitModeBean> {
        return mClientFactory.createLabClient()
            .indexStockList(mutableMap)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun warningNoticeList(mutableMap: Map<String, String>): Observable<EarlyWarningBean> {
        return mClientFactory.createLabClient()
            .warningNoticeList(mutableMap)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun warningNoticeDetail(id: String): Observable<ProcessedBean> {
        return mClientFactory.createLabClient()
            .warningNoticeDetail(id)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun handleMessage(noticeId: String, handleNotes: String): Observable<ProcessedBean> {
        return mClientFactory.createLabClient()
            .handleMessage(noticeId, handleNotes)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun warningNoticeCount(subId: String): Observable<String> {
        return mClientFactory.createLabClient()
            .warningNoticeCount(subId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun indexDetailsList(mutableMap: Map<String, String>): Observable<QueryTwoBean> {
        return mClientFactory.createLabClient()
            .indexDetailsList(mutableMap)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun useValidation(
        cardNum: String,
        subId: String,
        doorId: String
    ): Observable<UserValidationBean> {
        return mClientFactory.createLabClient()
            .useValidation(cardNum, subId, doorId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun aioScanLogin(subId: String, doorId: String, code: String): Observable<UserValidationBean> {
        return mClientFactory.createLabClient()
            .aioScanLogin(subId, doorId, code)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun lockOperate(map: Map<String, Any>): Observable<Boolean> {
        return mClientFactory.createLabClient()
            .lockOperate(map)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun outTimeWarn(map: Map<String, Any>): Observable<Boolean> {
        return mClientFactory.createLabClient()
            .outTimeWarn(map)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun getLocks(subId: String, lockNum: String): Observable<Boolean> {
        return mClientFactory.createLabClient()
            .getLocks(subId, lockNum)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun basicConfig(subId: String): Observable<ConfigBean> {
        return mClientFactory.createLabClient()
            .basicConfig(subId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun useRecords(map: Map<String, Any>): Observable<UseLedBean> {
        return mClientFactory.createLabClient()
            .useRecords(map)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun stockLedger(map: Map<String, Any>): Observable<InventoryListBean> {
        return mClientFactory.createLabClient()
            .stockLedger(map)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun useReturnList(subId: String): Observable<UseLedBean> {
        return mClientFactory.createLabClient()
            .useReturnList(subId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun tagDetailsList(map: Map<String, Any>): Observable<QueryTwoBean> {
        return mClientFactory.createLabClient()
            .tagDetailsList(map)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun getDetailsById(id: String): Observable<ReturnDetailsBean> {
        return mClientFactory.createLabClient()
            .getDetailsById(id)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun getMsdsDetails(searchValue: String?): Observable<MsdsBean> {
        return mClientFactory.createLabClient()
            .getMsdsDetails(searchValue)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun checkRfids(rfid: String): Observable<Boolean> {
        return mClientFactory.createLabClient()
            .checkRfids(rfid)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun controlConfigs(chemicalLevel: Int): Observable<ChemicalConfsBean> {
        return mClientFactory.createLabClient()
            .controlConfigs(chemicalLevel)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    fun getControlConfigs(chemicalLevel: Int): Observable<HxpControlConfig> {
        return mClientFactory.createLabClient()
            .getControlConfigs(chemicalLevel)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }


    /**
     * 上传APK更新状态
     *
     * @param state 0:升级失败; 1:升级成功; 2:升级中
     */
    fun onepcApkUpdate(id: String, state: String): Observable<Boolean> {
        return mClientFactory.createLabClient()
            .onepcApkUpdate(id, state)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }


    /**
     * 退出登录
     */
    fun loginOut(): Observable<Boolean> {
        return mClientFactory.createLabClient()
            .loginOut()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    /**
     * 监听每分钟进行调用
     */
    fun monitor(deviceNo: String): Observable<Boolean> {
        return mClientFactory.createLabClient()
            .monitor(deviceNo)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    /**
     * 人脸登录
     */
    fun faceCompare(file: File, param: FaceCompareReq): Observable<UserData> {
        return mClientFactory.createLabClient()
            .faceCompare(file, param)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    /**
     * 人脸  双人认证
     */
    fun checkUserFaceByPic(file: File, param: FaceCompareReq): Observable<UserValidationBean> {
        return mClientFactory.createLabClient()
            .checkUserFaceByPic(file, param)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

    /**
     * 双人验证 刷卡识别身份权限
     */
//    fun userValidation(map: Map<String, String>): Observable<UserValidationBean> {
//        return mClientFactory.createLabClient()
//            .userValidation(map)
//            .subscribeOn(Schedulers.io())
//            .observeOn(AndroidSchedulers.mainThread())
//    }

    /**
     * 双人验证 刷卡识别身份权限
     */
    fun useCardVerify(map: Map<String, String>): Observable<UserValidationBean> {
        return mClientFactory.createLabClient()
            .useCardVerify(map)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
    }

}