package com.lukouguoji.module_base.bean

import androidx.databinding.ObservableBoolean
import androidx.databinding.ObservableField
import com.lukouguoji.module_base.R
import com.lukouguoji.module_base.interfaces.ICheck
import com.lukouguoji.module_base.ktx.noNull
import dev.DevUtils
import dev.utils.DevFinal
import dev.utils.common.DateUtils

class GoodsTransportBean : ICheck {
    var activited: String = "" // null
    var allocationStatus: String = "" // null
    var boardType: String = "" // null
    var carId: String = "" // 012
    var carWeight: String = "" // null
    var cargoType: String = "" // null
    var cargoTypeName: String = "" //货物类型名称
    var cargoWeight: String = "" // null
    var carrier: String = "" // null
    var checkFlag: String = "" // null
    var copDate: String = "" // null
    var copId: String = "" // null
    var driver: String = "" // null
    var estimatedTakeOff: String = "" // 2024-06-25 21:00:00
    val estimatedTakeOffTime: String
        get() {
            return estimatedTakeOff.split(" ").lastOrNull().noNull()
        }
    val estimatedTakeOffHM: String
        get() {
            return DateUtils.parseString(
                estimatedTakeOff,
                DevFinal.TIME.yyyyMMddHHmmss_HYPHEN,
                "HH:mm"
            ).noNull(estimatedTakeOff)
        }
    //计划起飞
    var scheduledTackOff: String = "" // 2024-06-25 21:00:00
    val scheduledTackOffTime: String
        get() {
            return scheduledTackOff.split(" ").lastOrNull().noNull()
        }
    val scheduledTackOffHM: String
        get() {
            return DateUtils.parseString(
                scheduledTackOff,
                DevFinal.TIME.yyyyMMddHHmmss_HYPHEN,
                "HH:mm"
            ).noNull(scheduledTackOff)
        }
    var frontStationTime: String = "" // 前方站时间

    var fclose: String = "" // null
    var fdate: String = "" // 2024-06-25

    val fDateNoYear: String
        get() {
            var (year, mon, day) = fdate.split("-")
            return "$year$mon$day"
        }
    var fdep: String = "" // PEK
    var fdest: String = "" // HFE
    var flight: String = "" // null
    var fno: String = "" // MU2266
    var ldRemark: String = "" // null
    var locPriority: String = "" // null
    var location: String = "" // null
    var mailWeight: String = "" // null
    var maxWeight: String = "" // null
    var mcn: String = "" // null
    var netWeight: String = "" // null
    var opDate: String = "" // null
    var opId: String = "" // null
    var pc: String = "" // null
    var priority: String = "" // null
    var remark: String = "" // null
    var spCode: String = "" // null
    var spCodeStatus: String = "" // null
    var standId: String = "" // null

    // 0出港、1进港(转运页面判断)
    var status: String = "" // 1
    var storageArea: String = "" // null
    //    存放区域属性是否展示-----250326该字段改为前方站时间是否显示
    var storageAreaVisible: Boolean = false
    var tcn: String = "" // null
    var totalWeight: String = "" // null
    var transDate: String = "" // null

    // 转运起始站(1：出港库区，2：进港库区，3：转运区，4：出港机坪，5：进港机坪)
    var transDep: String = "" // 5

    // 转运目的站(1：出港库区，2：进港库区，3：转运区，4：出港机坪)
    var transDest: String = "" // 3

    // 转运标识（0：正常，1：退回，2：机坪流转）
    var transFlag: String = "" // 0
    var transId: String = "" // null

    // 运输状态 字典表code = TRANSSTATUS(0待运输、1开始运输、2完成运输)
    var transStatus: String = "" // 0

    val transStatusName: String = ""
    val transStatusColor: Int
        get() {
            return DevUtils.getTopActivity().resources.getColor(
                when (transStatus) {
                    "0" -> R.color.blue
                    "1" -> R.color.green
                    "2" -> R.color.red
                    else -> R.color.blue
                }
            )
        }
    var transType: String = "" // 3
    var uld: String = "" // null
    var uldWeight: String = "" // null
    var useId: String = "" // 34
    var username: String = "" // null
    var volume: String = "" // null

    // 结束状态  0 未结束、1已结束
    var endFlag: String = "" // null

    var range: String = "" // null
        get() {
            if (field.isEmpty()) {
                field = "$fdep-$fdest"
            }
            return field
        }

    // 选中状态
    val checked = ObservableBoolean(false)

    override fun getCheckObservable() = checked


    /**
     * 是否能退回
     */
    fun canReturn(): Boolean {
        return (transStatus == "2" && transType == "2") || (transStatus == "0" && transType == "3")
    }



    //    加货标识
    var addCargoFlag: String = ""

    val addCargoFlagName: String
        get() {
            return when (addCargoFlag) {
                "1" -> "待加货"
                "2" -> "完成加货"
                else -> ""
            }
        }
    //    完成加货时间
    var addCargoDate: String = ""

    //    完成加货人
    var addCargoId: String = ""

}