package com.za.bean

import com.blankj.utilcode.util.EncodeUtils
import com.blankj.utilcode.util.TimeUtils
import com.za.base.AppConfig
import java.io.Serializable
import java.nio.charset.StandardCharsets

data class JpushBean(
    val pushType: Int? = null, //0 新任务 1 任务取消 2 任务变更
    val taskId: Int? = null,//订单号       "taskId":5313005
    val taskCode: String? = null, //订单编码    "taskCode":"ZD20190308009965"
    val customerName: String? = null, //客户姓名  "customerName":"越继安"
    val customerPhone: String? = null, //客户电话  "customerPhone":"18078815268"
    val carBrand: String? = null, //车辆品牌   "carBrand":""
    val carModel: String? = null,//车辆型号  "carModel":"秦"
    val contract: String? = null, //车辆型号  "carModel":"秦"
    val typeDesc: String? = null, //推送的附加消息  revoke 撤回   giveUp放弃 reDispatch改派
	val userOrderId: Int? = null,
    val carNo: String? = null, //客户车车牌号  "carNo":"粤AF53918"
    val taskState: String? = null, //订单状态   "taskState":"GOTO"
    val address: String? = null, //任务地址   "address":"广东省广州市白云区107国道石井凰岗路342号(白云黄石、同德围地区近庆丰兴隆公园)美景大酒店"
    val addressProperty: String? = null,//任务地址类型   "addressProperty":"地面"
    val hotline: String? = null, //任务地址类型   "addressProperty":"地面"
    val schedulingFinalRule: Int? = null, //案件类型  0 传统案件 1 聚合派工
    val addressRemark: String? = null,
    val distAddress: String? = null, //目的地地址   "distAddress":"广东省广州市白云区雅岗南大道"
    val distAddressRemark: String? = null,
    val expectArriveTime: String? = null, //预计到达时间  "expectArriveTime":"2019-03-08 05:11:07"
    val serviceTypeName: String? = null,//服务类型 "serviceTypeName":"故障--平板拖车"
    val dispatchTime: String? = null, //派单时间  "dispatchTime":"2019-03-08 04:26:07"
    val lat: Double? = null,
    val lng: Double? = null,
    val distLat: Double? = null,
    val distLng: Double? = null,
    val importantTip: String? = null,
    val tipContent: String? = null,
    val settleType: Int?=null,//结算类型 1 月结 2 现金
    var orderSource: String? = null, //  "orderSource":"中道救援-比亚迪道路救援项目"
    val hasReplaceBatteryCapable: Int? = null ,//是否有更换电瓶的能力  1 搭电可以更换电瓶  2搭电不可以更换电瓶 其他的不展示
    var voiceType : Int?=null //语音提示类型  1小修单 2拖车单 3困境单
) : Serializable {
    fun isNeedCallCustomPhone(): Boolean {
        return "210" != customerPhone && "230" != customerPhone
    }
}


data class NewOrderRequestBean(val vehicleId: Int? = null)

//历史订单状态
data class HistoryTaskBean(
    val taskId: Int? = null, //订单号
    val taskCode: String? = null, //订单编码
    val userOrderId: Int? = null,
    val userOrderCode: String? = null, //只有电子工单历史补传才需要传
    val supplierAudit: Int? = null, //审核状态 0待补充  1 待审核 2审核不通过 3 审核通过
    val supplierAuditStr: String? = null, //审核状态描述
    val missingContent: String? = null, //缺失内容
    val auditFailReason: String? = null, //审核失败原因
    val customerName: String? = null, //客户姓名
    val customerPhone: String? = null, //客户电话
    val carBrand: String? = null, //车辆品牌
    val carModel: String? = null, //车辆型号
    val carNo: String? = null, //客户车车牌号  "
    val carVin: String? = null, //客户车Vin码
    val taskState: String? = null, //订单状态
    val address: String? = null, //任务地址
    val addressRemark: String? = null, //事发地地址补充
    val addressProperty: String? = null, //任务地址类型
    val lat: Double? = null,
    val lng: Double? = null,
    val distAddress: String? = null, //目的地地址
    val distAddressRemark: String? = null, //目的地地址补充
    val distLat: Double? = null,
    val distLng: Double? = null,
    val expectArriveTime: String? = null, //预计到达时间
    val serviceTypeName: String? = null, //服务类型
    val orderSource: String? = null, //
    val flowType: Int? = null, //流程类型  "flowType":2
    val settleType: Int? = null, //结算类型 1 月结 2 现金
    val supplierId: Int? = null,
    val successTime: String? = null, //完成时间  "dispatchTime":"2019-03-08 04:26:07"
    val verifyType: Int? = null, //验证类型 "verifyType":1
    val verifyValue: String? = null, //验证内容
    val holdon: Boolean? = null, //是否被挂起  "holdon":false
    val externalCode: String? = null, //流水号
    val vehicleName: String? = null,
    val traceIdAB: Int? = null,
    val mileageAB: Int? = null,
    val traceABUrl: String? = null,
    val traceIdBC: Int? = null,
    val mileageBC: Int? = null,
    val mileageCA: Int? = null,
    val traceBCUrl: String? = null,
    val createTime: String? = null,
    val acceptTime: String? = null,
    val arriveTime: String? = null,
    val arriveDestTime: String? = null,
    val giveupTime: String? = null,
    val giveupAddress: String? = null,
    val giveupLat: Double? = null,
    val giveupLng: Double? = null,
    val needWaterMarker: Boolean? = null,
    val needShowPhoneBrand: Boolean? = null,
    val policyNo: String? = null, // 平安拖车责任险 保单号

    val electronOrderState: String? = null,  //电子工单状态

    val hasReplaceBatteryCapable: Int? = null,  //是否具有更换电瓶的能力

    val hasReplaceBattery: Int = 0 //1已更换过  2有更换能力但没更换过 0无
) : Serializable {

    fun getEleOrderH5Url(): String? {
        if (electronOrderState == null || electronOrderState != "3") {
            return null
        }
        val paramQuery = (("userOrderId=$userOrderId").toString() + "&userOrderCode=" + taskCode) + "&supplierId=" + userOrderId
        return AppConfig.Resource_URL + "/electronicWorkOrder/index.html?" + EncodeUtils.base64Encode2String(paramQuery.toByteArray(StandardCharsets.UTF_8))
    }

    fun getSettleTypeStr(): String {
        return when (settleType) {
            1 -> {
                "月结"
            }

            2 -> {
                "现金"
            }

            else -> {
                ""
            }
        }
    }
}


data class HistoryPhotoTemplates(
    /**
     * 任务节点
     */
    val taskStatus: Int? = null,
    /**
     * 图片节点名称
     */
    val taskStatusString: String? = null,
    /**
     * 该节点下的所有历史照片信息
     */
    val photoList: List<HistoryPhotoTemplateItem>? = null
)

data class HistoryPhotoTemplateItem(
    val photoUrl: String? = null,
    val tag: String? = null,
    val imageTitle: String? = null,
    val lon: String? = null,
    val lat: String? = null,
    val templatePhotoType: Int = 0, //1 照片  2 工单照片
    val takePhotoTime: String? = null,
    val takeAddress: String? = null,
    val uploadStatus: String? = null,
    val uploadState: Int? = 0, //0 上传中  1 上传成功  2 上传失败
) {

    //获取拍照时间
    fun getPhotoTakeTime(taskState: String, historyTaskBean: HistoryTaskBean?): String? {
        if (!takePhotoTime.isNullOrBlank()) {
            return takePhotoTime
        }
        return when (taskState) {
            "13001", "15001" -> historyTaskBean?.arriveTime
            "17001" -> {
                if (2 == historyTaskBean?.flowType) {
                    historyTaskBean.arriveDestTime
                } else {
                    historyTaskBean?.arriveTime
                }
            }

            "18001" -> {
                historyTaskBean?.successTime
            }

            "18100" -> historyTaskBean?.giveupTime
            else -> TimeUtils.getNowString()
        }
    }

    fun getPhotoLat(taskState: String, historyTaskBean: HistoryTaskBean?): Double? {
        if (!lat.isNullOrBlank()) {
            return lat.toDouble()
        }
        return when (taskState) {
            "13001", "15001" -> historyTaskBean?.lat
            "17001", "18001" -> {
                if (2 == historyTaskBean?.flowType) {
                    historyTaskBean.distLat
                } else {
                    historyTaskBean?.lat
                }
            }

            "18100" -> historyTaskBean?.giveupLat
            else -> null
        }
    }

    fun getPhotoLng(taskState: String, historyTaskBean: HistoryTaskBean?): Double? {
        if (!lon.isNullOrBlank()) {
            return lon.toDouble()
        }
        return when (taskState) {
            "13001", "15001" -> historyTaskBean?.lng
            "17001", "18001" -> {
                if (2 == historyTaskBean?.flowType) {
                    historyTaskBean.distLng
                } else {
                    historyTaskBean?.lng
                }
            }

            "18100" -> historyTaskBean?.giveupLng
            else -> null
        }
    }

    fun getPhotoAddress(taskState: String, historyTaskBean: HistoryTaskBean?): String? {
        if (!takeAddress?.replace("[", "")?.replace("]", "").isNullOrBlank()) {
            return takeAddress
        }
        return when (taskState) {
            "13001", "15001" -> historyTaskBean?.address
            "17001", "18001" -> {
                if (2 == historyTaskBean?.flowType) {
                    historyTaskBean.distAddress
                } else {
                    historyTaskBean?.address
                }
            }

            "18100" -> historyTaskBean?.giveupAddress
            else -> ""
        }
    }

}


data class TaskSettlementAndTraceBean(
    val settleMap: SettleMapBean? = null,
    val traceIdAB: Int? = null,
    val mileageAB: Int? = null,
    val traceABUrl: String? = null,
    val traceIdBC: Int? = null,
    val mileageBC: Int? = null,
    val mileageCA: Int? = null,
    val traceBCUrl: String? = null
)

data class SettleMapBean(
    /*————————————子公司——————————*/
    val startPrice: Int? = null, //起步价
    val unitPrice: Double? = null, //每公里单价
    val mileage: Int? = null, //公里数
    val basePrice: Double? = null,//基本费用
    val roadFee: Int? = null,//路桥费
    val assistFee: Int? = null, //辅助总费用

    /*———————————————供应商———————————————*/ //        public Integer startMileage;//出发段公里数
    //        public Integer carryMileage;//背车段公里数
    //        public Integer backMileage;//回程段公里数
    val startRoadFee: Int? = null, //出发段过境费
    val carryRoadFee: Int? = null, //背车段过境费
    val backRoadFee: Int? = null, //回程段过境费
    val waitFee: Int? = null,//等候费
    val wheelFee: Int? = null,//辅助轮费
    val wheelNum: Int? = null, //辅助轮个数
    val wheelPrice: Int? = null, //辅助轮单价
    val dilemmaFee: Int? = null,//困境费
    val basementFee: Int? = null, //其他费用
    val totalFee: Double? = null,//费用总计
)


/**
 * Created by zhangj on 2019/12/4.
 */
class SettleInfoRequest(
    val orderId: Int? = null,
    val supplierType: Int? = null,
    val startMileage: Int? = null,
    val carryMileage: Int? = null,
    val backMileage: Int? = null,
    val startRoadFee: Int? = null,
    val carryRoadFee: Int? = null,
    val backRoadFee: Int? = null,
    val waitFee: Int? = null,
    val settleType: Int? = null,
    val wheelFee: Int? = null, //辅助轮费
    val wheelNum: Int? = null,
    val wheelPrice: Int? = null,
    val dilemmaFee: Int? = null, //困境费
    val basementFee: Int? = null, //其他费用
    val totalFee: Double? = null, //
    val startPrice: Int? = null,
    val unitPrice: Double? = null,
    val mileage: Int? = null,
    val basePrice: Double? = null,
    val assistFee: Int? = null,
    val imgInfo: String? = null,
    val imgPath: String? = null,
)

data class AMapTraceBean(
    val counts: Int? = null,
    val distance: Double? = null,
    val time: Long? = null,
    val trid: Int? = null,
    val points: List<PointsBean>? = null)

data class PointsBean(
    val accuracy: Double? = null,
    val direction: Double? = null,
    val height: Double? = null,
    val locatetime: Long? = null,
    val location: String? = null,
    val speed: Double? = null)