package com.abbidot.tracker.retrofit2

import com.abbidot.baselibrary.network.base.BaseNetworkApi
import com.abbidot.tracker.bean.FencesBean
import com.abbidot.tracker.bean.PayResultBean
import com.abbidot.tracker.bean.SetMealBean
import com.abbidot.tracker.bean.SubscriptionsOrderBean
import com.abbidot.tracker.constant.ConstantInt
import okhttp3.MultipartBody


/**
 * 网络请求具体实现
 * 需要部署服务端：https://github.com/huannan/XArchServer
 */
object NetworkApi : BaseNetworkApi<INetworkService>(INetworkService.BASE_URL) {

    /**
     * 获取国家代码号
     */
    suspend fun getCountryCodes() = getResult {
        service.getCountryCodes()
    }

    /**
     * 获取邮箱验证码
     * type验证码类型 1是注册 2是忘记密码
     */
    suspend fun requestVerificationCode(email: String, type: Int) = getResult {
        service.getVerificationCode(email, type)
    }

    /**
     * 验证码验证
     */
    suspend fun validateCode(email: String, emailCode: String, type: Int) = getResult {
        service.validateCode(email, emailCode, type)
    }

    /**
     * 注册/创建用户
     */
    suspend fun registerV2(email: String, password: String, userName: String, countryCode: String) =
        getResult {
            service.registerV2(email, password, userName, countryCode)
        }

    /**
     * 注册
     */
    suspend fun register(email: String, password: String, userName: String) = getResult {
        service.register(email, password, userName)
    }

    /**
     * 用户登陆
     */
    suspend fun login(email: String, password: String) = getResult {
        service.login(email, password)
    }

    /**
     * 获取用户信息
     */
    suspend fun getUserInfo(userId: String) = getResult {
        service.getUserInfo(userId)
    }

    /**
     * 用户注销
     */
    suspend fun logoff(userId: String) = getResult {
        service.logoff(userId)
    }

    /**
     *删除消息
     */
    suspend fun deleteMessage(messageIds: String) = getResult {
        service.deleteMessage(messageIds)
    }

    /**
     *用户意见反馈
     *  type=反馈问题类型 type 1为APP 2为设备 3其它
     */
    suspend fun feedback(
        type: Int, userId: String, content: String, imgurls: String, email: String
    ) = getResult {
        service.feedback(type, userId, content, imgurls, email)
    }

    /**
     *重置密码
     */
    suspend fun resetPassword(email: String, password: String) = getResult {
        service.resetPassword(email, password)
    }

    /**
     *修改单位
     */
    suspend fun updateMeasureUnit(userId: String, measurementUnit: Int) = getResult {
        service.updateMeasureUnit(userId, measurementUnit)
    }

    /**
     * 图片上传
     */
    suspend fun uploadImage(file: MultipartBody.Part) = getResult {
        service.uploadImage(file)
    }

    /**
     * 更新用户信息
     */
    suspend fun updateUser(
        email: String, userId: String, imgurl: String, countryCode: String, username: String
    ) = getResult {
        service.updateUser("", email, 0, userId, imgurl, "", username, countryCode)
    }

    /**
     * 获取消息列表
     */
    suspend fun getMessageList(userId: String) = getResult {
        service.getMessageList(userId)
    }

    /**
     * 获取未读消息数量
     */
    suspend fun getMessageUnReadCount(userId: String) = getResult {
        service.getMessageUnReadCount(userId)
    }

    /**
     * 获取消息列表
     */
    suspend fun messageListByPage(userId: String, page: Int) = getResult {
        service.messageListByPage(userId, page, 20)
    }

    /**
     * 设置全部消息已读
     */
    suspend fun setMessageAllIsRead(userId: String) = getResult {
        service.setMessageAllIsRead(userId)
    }

    /**
     * 设置单条消息已读
     */
    suspend fun setMessageIsRead(messageId: String) = getResult {
        service.setMessageIsRead(messageId)
    }

    /**
     * 获取蓝牙设备Mac
     */
    suspend fun getMacId(userId: String, deviceOutId: String) = getResult {
        service.getMacId(userId, deviceOutId)
    }

    /**
     * 获取设备iccid
     */
    suspend fun getIccId(deviceOutId: String) = getResult {
        service.getIccId(deviceOutId)
    }

    /**
     * 上电激活设备，更新状态
     */
    suspend fun updateStatus(deviceId: String, addStatus: Int) = getResult {
        service.updateStatus(deviceId, addStatus)
    }

    /**
     * 设备绑定
     */
    suspend fun bindDevice(userId: String, deviceOutId: String) = getResult {
        service.bindDevice(userId, deviceOutId, 1)
    }

    /**
     * 支付成功后，更新绑定状态
     */
    suspend fun updatePayDeviceState(deviceId: String, userId: String) = getResult {
        service.updatePayDeviceState(deviceId, userId)
    }

    /**
     * 获取设备订单状态
     */
    suspend fun getDeviceOrderStatus(deviceOutId: String) = getResult {
        service.getDeviceOrderStatus(deviceOutId)
    }

    /**
     * 解绑删除设备
     */
    suspend fun unbindDevice(userId: String, deviceId: String) = getResult {
        service.unbindDevice(userId, deviceId)
    }

    /**
     * 获取设备列表
     */
    suspend fun getDeviceList(userId: String, type: Int) = getResult {
        service.getDeviceList(userId, type)
    }

    /**
     * 获取未绑定宠物的设备
     */
    suspend fun getUnboundDevices(userId: String) = getResult {
        service.getUnboundDevices(userId)
    }

    /**
     * 把Tracker给分配宠物
     */
    suspend fun assignOtherPetTracker(
        userId: String, petId: String, originDeviceId: String, assignDeviceId: String
    ) = getResult {
        service.assignOtherPetTracker(userId, petId, originDeviceId, assignDeviceId)
    }

    /**
     * 给已绑定的设备分配宠物
     */
    suspend fun assignOtherPet(
        userId: String, deviceId: String, originPetId: String, assignPetId: String
    ) = getResult {
        service.assignOtherPet(userId, deviceId, originPetId, assignPetId)
    }

    /**
     * 获取地图模块的设备数据
     */
    suspend fun getPetTrackerInfo(deviceId: String) = getResult {
        service.getPetTrackerInfo(deviceId)
    }

    /**
     * 获取设备详情
     */
    suspend fun getDeviceDetail(deviceId: String) = getResult {
        service.getDeviceDetail(deviceId)
    }

    /**
     * 添加圆形围栏
     */
    suspend fun addCircleFence(fencesBean: FencesBean) = getResult {
        service.addCircleFence(
            fencesBean.deviceId,
            fencesBean.deviceServiceId,
            fencesBean.name,
            fencesBean.address,
            "",
            1,
            fencesBean.radius,
            fencesBean.fenceType,
            1,
            fencesBean.fenceNameType,
            fencesBean.latitudeCenter,
            fencesBean.longitudeCenter,
            fencesBean.ancillaryLatitude,
            fencesBean.ancillaryLongitude,
            fencesBean.ancillaryOtherLatitude,
            fencesBean.ancillaryOtherLongitude,
            fencesBean.fenceId,
            fencesBean.modeType
        )
    }

    /**
     * 添加矩形围栏
     */
    suspend fun addRectFence(fencesBean: FencesBean) = getResult {
        service.addRectFence(
            fencesBean.deviceId,
            fencesBean.deviceServiceId,
            fencesBean.name,
            fencesBean.address,
            "",
            1,
            fencesBean.fenceType,
            2,
            fencesBean.fenceNameType,
            fencesBean.longitudeA,
            fencesBean.latitudeA,
            fencesBean.longitudeB,
            fencesBean.latitudeB,
            fencesBean.longitudeC,
            fencesBean.latitudeC,
            fencesBean.longitudeD,
            fencesBean.latitudeD,
            fencesBean.longitudeCenter,
            fencesBean.latitudeCenter,
            fencesBean.longDistance,
            fencesBean.shortDistance,
            fencesBean.fenceId,
            fencesBean.modeType
        )
    }

    /**
     * 添加多边形形围栏
     */
    suspend fun addPolygonFence(fencesBean: FencesBean) = getResult {
        service.addPolygonFence(
            fencesBean.deviceId,
            fencesBean.deviceServiceId,
            fencesBean.name,
            fencesBean.address,
            "",
            1,
            fencesBean.fenceType,
            3,
            fencesBean.fenceNameType,
            fencesBean.longitudeA,
            fencesBean.latitudeA,
            fencesBean.longitudeB,
            fencesBean.latitudeB,
            fencesBean.longitudeC,
            fencesBean.latitudeC,
            fencesBean.longitudeD,
            fencesBean.latitudeD,
            fencesBean.longitudeE,
            fencesBean.latitudeE,
            fencesBean.longitudeF,
            fencesBean.latitudeF,
            fencesBean.longitudeCenter,
            fencesBean.latitudeCenter,
            fencesBean.fenceId,
            fencesBean.modeType
        )
    }

    /**
     * 更新圆形围栏
     */
    suspend fun updateCircleFence(
        deviceId: String,
        deviceServiceId: String,
        name: String,
        address: String,
        imgurl: String,
        isOn: Int,
        radius: Int,
        longitudeCenter: Double,
        latitudeCenter: Double,
        fenceNameType: Int,
        fenceType: Int,
        fenceId: String,
        ancillaryLatitude: Double,
        ancillaryLongitude: Double,
        ancillaryOtherLatitude: Double,
        ancillaryOtherLongitude: Double,
        modeType: Int
    ) = getResult {
        service.updateCircleFence(
            deviceId,
            deviceServiceId,
            name,
            address,
            imgurl,
            isOn,
            radius,
            longitudeCenter,
            latitudeCenter,
            1,
            fenceType,
            fenceNameType,
            fenceId,
            ancillaryLatitude,
            ancillaryLongitude,
            ancillaryOtherLatitude,
            ancillaryOtherLongitude,
            modeType
        )
    }

    /**
     * 更新矩形围栏
     */
    suspend fun updateRectFence(
        deviceId: String,
        deviceServiceId: String,
        name: String,
        address: String,
        imgurl: String,
        isOn: Int,
        fenceNameType: Int,
        fenceType: Int,
        fenceId: String,
        longitudeA: Double,
        latitudeA: Double,
        longitudeB: Double,
        latitudeB: Double,
        longitudeC: Double,
        latitudeC: Double,
        longitudeD: Double,
        latitudeD: Double,
        longitudeCenter: Double,
        latitudeCenter: Double,
        longDistance: Int,
        shortDistance: Int,
        modeType: Int
    ) = getResult {
        service.updateRectFence(
            deviceId,
            deviceServiceId,
            name,
            address,
            imgurl,
            isOn,
            2,
            fenceType,
            fenceNameType,
            fenceId,
            longitudeA,
            latitudeA,
            longitudeB,
            latitudeB,
            longitudeC,
            latitudeC,
            longitudeD,
            latitudeD,
            longitudeCenter,
            latitudeCenter,
            longDistance,
            shortDistance,
            modeType
        )
    }

    /**
     * 更新多边形围栏
     */
    suspend fun updatePolygonFence(fencesBean: FencesBean) = getResult {
        service.updatePolygonFence(
            fencesBean.deviceId,
            fencesBean.deviceServiceId,
            fencesBean.fenceId,
            fencesBean.name,
            fencesBean.address,
            "",
            fencesBean.isOn,
            fencesBean.fenceType,
            3,
            fencesBean.fenceNameType,
            fencesBean.longitudeA,
            fencesBean.latitudeA,
            fencesBean.longitudeB,
            fencesBean.latitudeB,
            fencesBean.longitudeC,
            fencesBean.latitudeC,
            fencesBean.longitudeD,
            fencesBean.latitudeD,
            fencesBean.longitudeE,
            fencesBean.latitudeE,
            fencesBean.longitudeF,
            fencesBean.latitudeF,
            fencesBean.longitudeCenter,
            fencesBean.latitudeCenter,
            fencesBean.modeType
        )
    }

    /**
     * 获取围栏列表
     */
    suspend fun getFenceList(deviceId: String) = getResult {
        service.getFenceList(deviceId)
    }

    /**
     * 移除围栏
     */
    suspend fun removeFence(fenceId: String, deviceServiceId: String, modeType: Int) = getResult {
        service.removeFence(fenceId, deviceServiceId, modeType)
    }

    /**
     * 获取wifi区域列表
     */
    suspend fun getWifiZoneList(deviceId: String) = getResult {
        service.getWifiZoneList(deviceId)
    }

    /**
     * 添加wifi区域
     */
    suspend fun addWifiZone(
        deviceId: String,
        wifiZoneName: String,
        address: String,
        wifiMac: String,
        wifiName: String,
        longitude: Double,
        latitude: Double,
        wifiPass: String,
        wifiAuth: Int,
        type: Int
    ) = getResult {
        service.addWifiZone(
            deviceId,
            wifiZoneName,
            address,
            wifiMac,
            wifiName,
            longitude,
            latitude,
            wifiPass,
            wifiAuth,
            type
        )
    }

    /**
     * 更新wifi区域
     */
    suspend fun updateWifiZone(
        wifiZoneId: String,
        deviceId: String,
        wifiZoneName: String,
        address: String,
        wifiMac: String,
        wifiName: String,
        longitude: Double,
        latitude: Double,
        type: Int
    ) = getResult {
        service.updateWifiZone(
            wifiZoneId,
            deviceId,
            wifiZoneName,
            address,
            wifiMac,
            wifiName,
            longitude,
            latitude,
            type
        )
    }

    /**
     * 删除wifi区域
     */
    suspend fun removeWifiZone(wifiZoneId: String) = getResult {
        service.removeWifiZone(wifiZoneId)
    }


    /**
     * 获取所有的宠物列表
     */
    suspend fun getPetList(userId: String, type: Int) = getResult {
        service.getPetList(userId, type)
    }

    /**
     * 获取未绑定的宠物列表
     */
    suspend fun getUnbindPetList(userId: String) = getResult {
        service.getUnbindPetList(userId)
    }

    /**
     * 获取首页宠物列表
     */
    suspend fun getHomeBindPetList(userId: String) = getResult {
        service.getHomeBindPetList(userId)
    }

    /**
     * 获取宠物标签
     */
    suspend fun getPetLabels() = getResult {
        service.getPetLabels()
    }

    /**
     * 添加宠物
     */
    suspend fun addPet(
        userId: String,
        petName: String,
        breed: String,
        gender: Int,
        petType: Int,
        birthdayDate: String,
        imgurl: String,
        weight: Float,
        height: Float,
        labels: String
    ) = getResult {
        service.addPet(
            userId, petName, breed, gender, petType, birthdayDate, imgurl, weight, height, labels
        )
    }

    /**
     * 更新宠物信息
     */
    suspend fun updatePetInfo(
        userId: String,
        petName: String,
        breed: String,
        gender: Int,
        petType: Int,
        birthdayDate: String,
        petId: String,
        imgurl: String,
        weight: Float,
        height: Float,
        labels: String
    ) = getResult {
        service.updatePetInfo(
            userId,
            petName,
            breed,
            gender,
            petType,
            birthdayDate,
            petId,
            imgurl,
            weight,
            height,
            labels
        )
    }

    /**
     * 解绑宠物
     */
    suspend fun unbindPet(userId: String, deviceId: String, petId: String) = getResult {
        service.unbindPet(userId, deviceId, petId)
    }

    /**
     * 绑定关联宠物
     */
    suspend fun bindPet(userId: String, deviceId: String, petId: String) = getResult {
        service.bindPet(userId, deviceId, petId)
    }

    /**
     * 获取宠物信息
     */
    suspend fun getPetAllInfo(petId: String) = getResult {
        service.getPetAllInfo(petId)
    }

    /**
     * 获取宠物信息
     */
    suspend fun getPetInfo(petId: String) = getResult {
        service.getPetInfo(petId)
    }

    /**
     * 获取宠物活动统计
     */
    suspend fun getPetActivityDetailInfo(petId: String, deviceId: String) = getResult {
        service.getPetActivityDetailInfo(petId, deviceId)
    }

    /**
     * 删除宠物
     */
    suspend fun deletePet(userId: String, petId: String) = getResult {
        service.deletePet(userId, petId)
    }

    /**
     * 获取设备家庭列表
     */
    suspend fun getFamilies(deviceId: String) = getResult {
        service.getFamilies(deviceId)
    }

    /**
     * 获取设备邀请信息
     */
    suspend fun getDeviceInviteInfo(email: String) = getResult {
        service.getDeviceInviteInfo(email)
    }

    /**
     * 设备邀请
     */
    suspend fun invite(
        userId: String,
        userName: String,
        sendEmail: String,
        deviceId: String,
        acceptEmail: String,
        relation: Int,//关系 1 Family 2 friend 3 love 4 colleague
        avatar: Int,//头像 1 男生 2 女生 3 未知
        petId: String,
        petName: String
    ) = getResult {
        service.invite(
            userId, userName, sendEmail, deviceId, acceptEmail, relation, avatar, petId, petName
        )
    }

    /**
     * 设备邀请
     */
    suspend fun inviteCN(userId: String, userName: String, deviceId: String, phone: String) =
        getResult {
            service.inviteCN(userId, userName, deviceId, phone)
        }

    /**
     * 删除家庭账户
     */
    suspend fun removeFamily(familyId: String) = getResult {
        service.removeFamily(familyId)
    }

    /**
     * 获取首页Data模块的设备数据
     */
    suspend fun getDeviceData(deviceId: String, dayTime: String, petId: String) = getResult {
        service.getDeviceData(deviceId, dayTime, petId)
    }

    /**
     * 获取ActiveTime数据
     */
    suspend fun getActiveTimeByDay(deviceId: String, dayTime: String, petId: String) = getResult {
        service.getActiveTimeByDay(deviceId, dayTime, petId)
    }

    /**
     * 获取SleepTime数据
     */
    suspend fun getSleepTimeByDay(deviceId: String, dayTime: String, petId: String) = getResult {
        service.getSleepTimeByDay(deviceId, dayTime, petId)
    }

    /**
     * 获取HistoryByDay数据
     */
    suspend fun getHistoryByDay(deviceId: String, fromTime: Long, toTime: Long) = getResult {
        service.getHistoryByDay(deviceId, fromTime, toTime)
    }

    /**
     * 获取设备进出围栏历史数据
     */
    suspend fun getHistoryFenceList(deviceId: String, fromTime: Long, toTime: Long) = getResult {
        service.getHistoryFenceList(deviceId, fromTime, toTime)
    }

    /**
     * 设置运动目标
     */
    suspend fun setGoal(deviceId: String, goalTime: Int) = getResult {
        service.setGoal(deviceId, goalTime)
    }

    /**
     * 获取地图模块的设备数据
     */
    suspend fun getMapDeviceStatus(deviceId: String) = getResult {
        service.getMapDeviceStatus(deviceId)
    }

    /**
     * 设备一键定位
     */
    suspend fun setupRefreshLocation(deviceId: String) = getResult {
        service.setupRefreshLocation(deviceId)
    }

    /**
     * 打开关闭直播
     */
    suspend fun setupDeviceLiveStatus(deviceId: String, liveState: Int, modeType: Int) = getResult {
        service.setupDeviceLiveStatus(deviceId, liveState, 0, modeType)
    }

    /**
     * 直播宠物轨迹
     */
    suspend fun getPetLivePoint(deviceId: String, timeStamp: Long) = getResult {
        service.getPetLivePoint(deviceId, timeStamp)
    }

    /**
     * 获取所有设备的e-sim卡
     */
    suspend fun getCards(userId: String) = getResult {
        service.getCards(userId)
    }

    /**
     * 获取设备的充值记录
     */
    suspend fun getRechargeHistory(deviceId: String) = getResult {
        service.getRechargeHistory(deviceId)
    }

    /**
     * 取消自动续费/自动订阅
     */
    suspend fun cancelSubscriptions(orderId: String, payType: Int, subscriptionId: String) =
        getResult {
            service.cancelSubscriptions(orderId, payType, subscriptionId)
        }

    /**
     * 自动续费,自动订阅
     */
    suspend fun subscription(
        feePackage: String,
        deviceId: String,
        accountFee: String,
        subscriptionFee: String,
        period: String,
        userId: String,
        username: String
    ) = getResult {
        service.subscription(
            feePackage, deviceId, accountFee, subscriptionFee, period, userId, username
        )
    }

    /**
     * 获取套餐列表
     */
    suspend fun getSetMealList() = getResult {
        service.getSetMealList()
    }

    /**
     * 获取订单号
     */
    suspend fun getPaypalOrderNo(
        mealName: String, description: String, totalCost: String, deviceId: String
    ) = getResult {
        service.getPaypalOrderNo(mealName, description, totalCost, deviceId)
    }

    /**
     * 信用卡发起支付
     */
    suspend fun cardPayment(
        mealName: String,
        mealDays: Int,
        totalCost: String,
        paymentMethodNonce: String,
        deviceId: String
    ) = getResult {
        service.cardPayment(mealName, mealDays, totalCost, paymentMethodNonce, deviceId)
    }

    /**
     * 信用卡自动订阅
     */
    suspend fun cardSubscription(
        userId: String,
        paymentMethodNonce: String,
        firstName: String,
        lastName: String,
        username: String,
        deviceId: String,
        setMealBean: SetMealBean
    ) = getResult {
        service.cardSubscription(
            userId,
            paymentMethodNonce,
            firstName,
            lastName,
            setMealBean.name,
            deviceId,
            setMealBean.accountFee,
            setMealBean.period,
            username,
            setMealBean.planId
        )
    }

    /**
     * 更新订单状态
     * @param orderStatus:0待支付 1是支付成功 2是取消支付/失败
     */
    suspend fun updateOrderStatus(
        orderId: String, orderStatus: Int, deviceId: String, mealDays: Int
    ) = getResult {
        service.updateOrderStatus(orderId, orderStatus, deviceId, mealDays)
    }

    /**
     * 获取braintree客户端令牌
     */
    suspend fun getBraintreeClientToken() = getResult {
        service.getBraintreeClientToken()
    }

    /**
     * 关闭设备
     */
    suspend fun turnoff(deviceInfoId: String, turnOff: Int) = getResult {
        service.turnoff(deviceInfoId, turnOff, 1)
    }

    /**
     * 设置设备上报下发时间
     */
    suspend fun reportInterval(deviceInfoId: String, gnssInterval: Int, modeType: Int) = getResult {
        service.reportInterval(deviceInfoId, gnssInterval, modeType)
    }

    /**
     * 设置设备的直播时间
     */
    suspend fun setLiveTime(deviceId: String, liveTime: Int) = getResult {
        service.setLiveTime(deviceId, liveTime)
    }

    /**
     * 设置ledSwitch开关
     */
    suspend fun setLedSwitch(deviceInfoId: String, ledSwitch: Int, modeType: Int) = getResult {
        service.setLedSwitch(deviceInfoId, ledSwitch, modeType)
    }

    /**
     * 设置light灯光
     */
    suspend fun setLedLight(
        deviceServerId: String,
        red: Int,
        green: Int,
        blue: Int,
        lightMode: Int,
        ledSwitch: Int,
        modeType: Int
    ) = getResult {
        service.setLedLight(deviceServerId, red, green, blue, lightMode, ledSwitch, modeType)
    }

    /**
     * 获取固件信息
     */
    suspend fun getFirmware(deviceName: String) = getResult {
        service.getFirmware(deviceName)
    }

    /**
     * 获取sim卡餐列表
     */
    suspend fun getSimSetMealList(
        iccId: String, partnerCode: String
    ) = getResult {
        service.getSimSetMealList(iccId, partnerCode)
    }

    /**
     * 获取Stripe支付凭证
     */
    suspend fun getStripePayOrder(
        amount: String,
        userId: String,
        feePackage: String,
        deviceId: String,
        username: String,
        cost: String,
        priceId: String,
        partnerCode: String,
        packageCode: String,
        servicePlanCode: String,
        orderPeriod: String,
        servicePlanShowName: String,
        deviceCode: String,
        autoRenewal: String
    ) = getResult {
        service.getStripePayOrder(
            amount,
            userId,
            feePackage,
            deviceId,
            username,
            cost,
            priceId,
            partnerCode,
            packageCode,
            servicePlanCode,
            orderPeriod,
            servicePlanShowName,
            deviceCode,
            autoRenewal
        )
    }

    /**
     * Stripe支付创建消费用户
     */
    suspend fun createCustomer(
        param: String, userId: String, userName: String, email: String
    ) = getResult {
        service.createCustomer(param, userId, userName, email)
    }

    /**
     * Stripe支付创建订阅
     */
    suspend fun createSubscription(
        userId: String,
        feePackage: String,
        deviceId: String,
        username: String,
        cost: String,
        priceId: String,
        customerId: String,
        amount: String,
        partnerCode: String,
        packageCode: String,
        servicePlanCode: String,
        orderPeriod: String,
        servicePlanShowName: String,
        deviceCode: String,
        autoRenewal: String
    ) = getResult {
        service.createSubscription(
            userId,
            feePackage,
            deviceId,
            username,
            cost,
            priceId,
            customerId,
            amount,
            partnerCode,
            packageCode,
            servicePlanCode,
            orderPeriod,
            servicePlanShowName,
            deviceCode,
            autoRenewal
        )
    }

    /**
     * Stripe支付取消订阅
     */
    suspend fun cancelStripeSubscription(
        orderId: String, subscriptionId: String, iccid: String
    ) = getResult {
        service.cancelStripeSubscription(orderId, subscriptionId, iccid)
    }

    /**
     * Stripe支付 Rsa算法解密测试
     */
    suspend fun rsaDecodeTest(encryptedData: String) = getResult {
        service.rsaDecodeTest(encryptedData)
    }

    /*******************************************以下是国内版本接口***********************************/
    /**
     * 微信登录
     */
    suspend fun wxLogin(code: String) = getResult {
        service.wxLogin(code)
    }

    /**
     * 微信绑定
     */
    suspend fun wxBind(phone: String, verificationCode: String, wxId: String) = getResult {
        service.wxBind(phone, verificationCode, wxId)
    }

    /**
     * 发送验证码
     */
    suspend fun sendCode(phone: String, type: Int) = getResult {
        service.sendCode(phone, type)
    }

    /**
     * 手机号验证码验证
     */
    suspend fun validatePhoneCode(phone: String, code: String, type: Int) = getResult {
        service.validatePhoneCode(phone, code, type)
    }

    /**
     * 验证码登录
     */
    suspend fun phoneLogin(phone: String, verificationCode: String) = getResult {
        service.phoneLogin(phone, verificationCode)
    }

    /**
     * 账号密码登录
     */
    suspend fun accountPasswordLogin(phone: String, password: String) = getResult {
        service.accountPasswordLogin(phone, password)
    }

    /**
     * 用户注册
     */
    suspend fun register(phone: String, password: String) = getResult {
        service.register(phone, password)
    }

    /**
     * 重置密码
     */
    suspend fun resetNewPassword(phone: String, password: String) = getResult {
        service.resetNewPassword(phone, password)
    }

    /**
     * 获取微信Prepay_id
     */
    suspend fun getWxPayOrder(
        setMealBean: SetMealBean, deviceId: String, userId: String, username: String
    ) = getResult {
        service.getWxPayOrder(
            setMealBean.name, deviceId, setMealBean.accountFee, setMealBean.period, userId, username
        )
    }

    /**
     * 获取支付宝支付订单
     */
    suspend fun getAlipayOrder(
        setMealBean: SetMealBean, deviceId: String, userId: String, username: String
    ) = getResult {
        service.getAlipayOrder(
            setMealBean.name, deviceId, setMealBean.accountFee, setMealBean.period, userId, username
        )
    }

    /**
     * 获取订阅订单列表
     */
    suspend fun getSubscriptionsOrder(userId: String) = getResult {
        service.getSubscriptionsOrder(userId)
    }

    /**
     * 获取套餐计划类型
     */
    suspend fun getPackageType() = getResult {
        service.getPackageType()
    }

    /**
     * 获取套餐列表
     */
    suspend fun getPackageList(planTypeName: String) = getResult {
        service.getPackageList(planTypeName)
    }

    /**
     * 获取设备充值得的历史记录
     */
    suspend fun getSubscriptionsHistory(userId: String, deviceId: String) = getResult {
        service.getSubscriptionsHistory(userId, deviceId)
    }

    /**
     * 获取设备充值得的历史记录(包括自动续订)
     */
    suspend fun getHistoryIncludeRenew(subscriptionId: String) = getResult {
        service.getHistoryIncludeRenew(subscriptionId)
    }

    /**
     * 获取设备充值得的历史记录
     */
    suspend fun commitRefund(
        currencyCode: String,
        orderId: String,
        chargeId: String,
        amount: Int,
        subscriptionId: String,
        planName: String,
        refundDescription: String,
        deviceId: String,
        deviceOutId: String,
        payType: Int
    ) = getResult {
        service.commitRefund(
            currencyCode,
            orderId,
            chargeId,
            amount,
            subscriptionId,
            planName,
            refundDescription,
            deviceId,
            deviceOutId,
            payType
        )
    }

    /**
     * 退款
     */
    suspend fun refund(orderNum: String) = getResult {
        service.refund(orderNum)
    }

    /**
     * 更新订阅状态 状态 0是取消 1使其变为正常
     */
    suspend fun updateSubscriptionStatus(subscriptionId: String, status: Int) = getResult {
        service.updateSubscriptionStatus(subscriptionId, status)
    }

    /**
     * 获取具体国家地区税率
     */
    suspend fun getTaxRateByRegionName(countryCode: String, regionName: String) = getResult {
        service.getTaxRateByRegionName(countryCode, regionName)
    }

    /**
     * 获取SIM卡重新激活费用
     */
    suspend fun getReactivationFee(orderId: String) = getResult {
        service.getReactivationFee(orderId)
    }

    /**
     * 创建Stripe订单发起支付
     */
    suspend fun createStripeOrder(subscriptionsOrder: SubscriptionsOrderBean): Result<PayResultBean> {
        subscriptionsOrder.apply {
            if (isUpdateOrder == ConstantInt.Type0) {
                orderNum = ""
                subscriptionId = ""
            }
            return getResult {
                service.createStripeOrder(
                    userId,
                    deviceId,
                    1,
                    iccid,
                    deviceOutId,
                    username,
                    mealName,
                    mealDesc,
                    mealId,
                    mealPeriod,
                    mealPrice,
                    mealDiscountPrice,
                    mealUnit,
                    annualCareType,
                    annualCarePrice,
                    reactivation,
                    reactivatePrice,
                    totalAmountWithTax,
                    planCategory,
                    autoRenewPrice,
                    tax,
                    customerId,
                    orderNum,
                    isUpdateOrder,
                    planTimeMonthsCount,
                    subscriptionId
                )
            }
        }
    }

    /**
     * 创建Paypal订单发起支付
     */
    suspend fun createPaypalOrder(subscriptionsOrder: SubscriptionsOrderBean): Result<PayResultBean> {
        subscriptionsOrder.apply {
            if (isUpdateOrder == ConstantInt.Type0) {
                orderNum = ""
                subscriptionId = ""
            }
            return getResult {
                service.createPaypalOrder(
                    userId,
                    deviceId,
                    2,
                    iccid,
                    deviceOutId,
                    username,
                    mealName,
                    mealDesc,
                    mealId,
                    mealPeriod,
                    mealPrice,
                    mealDiscountPrice,
                    mealUnit,
                    annualCareType,
                    annualCarePrice,
                    reactivation,
                    reactivatePrice,
                    totalAmountWithTax,
                    planCategory,
                    autoRenewPrice,
                    tax,
                    "",
                    orderNum,
                    isUpdateOrder,
                    planTimeMonthsCount,
                    subscriptionId
                )
            }
        }
    }

    /**
     * 获取通知设置
     */
    suspend fun getNotificationSet(userId: String) = getResult {
        service.getNotificationSet(userId)
    }

    /**
     * 消息通知设置
     */
    suspend fun setNotification(userId: String, notificationType: Int, status: Int) = getResult {
        service.setNotification(userId, notificationType, status)
    }

    /**
     * 设备日志上传
     */
    suspend fun uploadLog(file: MultipartBody.Part) = getResult {
        service.uploadLog(file)
    }

    /**
     * 上传设备日志
     */
    suspend fun uploadDeviceLog(
        deviceOutId: String, uploadTime: String, macID: String, logFileUrl: String
    ) = getResult {
        service.uploadDeviceLog(deviceOutId, uploadTime, macID, logFileUrl)
    }
}