package com.zj365.mime.vm

import androidx.lifecycle.MutableLiveData
import com.xty.base.vm.BaseVm
import com.xty.network.model.RespBody
import com.xty.network.model.SmsBean
import okhttp3.MultipartBody
import java.io.File

class DeviceSettingVm:BaseVm() {

    val smsListLive by lazy { MutableLiveData<RespBody<SmsBean>>() }
    val smsSettingLive by lazy { MutableLiveData<RespBody<Any>>() }

    /**
     * 短信开关列表
     */
    fun getSmsList() {
        startHttp {
            var response = apiInterface().smsList()
            response.getCodeStatus(smsListLive, nowData)
        }
    }


    /**
     * 短信开关设置
     *
     * @param path 签名文件地址
     * @param type 1:sms预警短信
     * @param state 1:打开 0：关闭
     *
     */
    fun smsSetting(path: String?, type: Int, state: Int) {

        startHttp {
            if (path.isNullOrEmpty()) {
                var body = apiInterface().smsSetting(type, state)
                body.getCodeStatus(smsSettingLive, nowData)
            } else {
                var file = File(path)
                var part = MultipartBody.Part.createFormData(
                    "file",
                    file.name,
                    retrofits.getMultiPartFileRb(file)
                )
                var body = apiInterface().smsSetting(part, type, state)
                body.getCodeStatus(smsSettingLive, nowData)
            }
        }
    }
}