package com.lukouguoji.module_base.bean

import com.lukouguoji.module_base.ktx.limit
import com.lukouguoji.module_base.ktx.noNull

class GcjBoxAddReqBean(
    // 装载id
    var locId: String = "",
    // 总件数
    var pc: Int = 0,
    // 总重量
    var totalWeight: String = "",
    var gjcLoading: GjcBoxAddLoadingReqBean? = null,
    var warehousePclistDTOList: List<GjcBoxAddWarehousePclistDTOListReqBean>? = null,
) {

    fun setGjcBoxAddList(list: List<GjcBoxAddListBean>, uldWeight: String) {
        // 全部是邮件
        var allMail = true
        // 总重量
        var totalWeight = 0.0
        var mailWeight = 0.0
        // 总体积
        var totalVolume = 0.0
        var mailVolume = 0.0
        // 总件数
        var totalPc = 0
        var mailpc = 0
        list.forEach {
            if (allMail && !it.waybillBean.isMail()) {
                allMail = false
            }
            val count = if (it.jianList.isEmpty()) it.waybillBean.pc.noNull("0")
                .toInt() else it.jianList.size
            totalWeight += (it.waybillBean.weight.noNull("0.0").toDouble())
            totalVolume += (it.waybillBean.volume.noNull("0.0").toDouble())
            totalPc += count
            if (it.waybillBean.isMail()) {
                mailWeight += it.waybillBean.weight.noNull("0.0").toDouble()
                mailVolume += it.waybillBean.volume.noNull("0.0").toDouble()
                mailpc += count
            }
        }

        pc = totalPc
        this.totalWeight = totalWeight.limit()
        gjcLoading = GjcBoxAddLoadingReqBean(
            cargotype = if (allMail) "1" else "0",
            cargoweight = totalWeight.limit(),
            locId = locId,
            mailpc = mailpc,
            mailvolume = mailVolume.limit(),
            mailweight = mailWeight.limit(),
            netweight = (totalWeight + uldWeight.toDouble()).limit(),
            pc = totalPc.toString(),
            volume = totalVolume.limit(),
        )

        warehousePclistDTOList = list.map {
            GjcBoxAddWarehousePclistDTOListReqBean(
                whid = it.waybillBean.whid.noNull(),
                prefix = it.waybillBean.prefix.noNull(),
                pc = it.jianList.size.toString(),
                pclist = GjcBoxAddPcListReqBean(
                    list = it.jianList.joinToString(",") { jianBean ->
                        jianBean.value
                    },
                    locId = locId,
                    no = it.waybillBean.no.noNull(),
                    pcID = it.pcID.noNull(),
                    prefix = it.waybillBean.prefix.noNull(),
                )
            )
        }
    }

}

class GjcBoxAddLoadingReqBean(
    // 仓库列表记录前缀都为000  为M    其他状况为C
    var cargotype: String = "C",
    // 仅累加仓库货物货重 必填
    var cargoweight: String = "",
    // 装载id
    var locId: String = "",
    // 货邮混装时，邮件件数（C类型时有效）   必填 累加仓库货物类型为邮件的件数
    var mailpc: Int = 0,
    // 货邮混装时，邮件体积（C类型时有效）	必填 累加仓库货物类型为邮件的体积
    var mailvolume: String = "",
    // 货邮混装时，邮件重量（C类型时有效） 	必填 累加仓库货物类型为邮件的重量
    var mailweight: String = "",
    // 净重量 货总重+ULD重 必填
    var netweight: String = "",
    // 累加仓库货物的件数
    var pc: String = "",
    // 优先级 默认0
    var priority: String = "0",
    // 累加仓库货物的体积
    var volume: String = "",
) {

}

class GjcBoxAddWarehousePclistDTOListReqBean(
    // 必填仓库id
    var whid: String = "",
    // 主提运单前缀(承运人运单三字码)  为000时表示该货物类型是邮件
    var prefix: String = "",
    // 件数
    var pc: String = "",
    // 件号对象
    var pclist: GjcBoxAddPcListReqBean? = null,
)

class GjcBoxAddPcListReqBean(
    // 物品件号列表 以‘,’（英文逗号）分割 必填
    var list: String = "",
    // 装载id	必填
    var locId: String = "",
    // 运单号
    var no: String = "",
    // 件号表id  新增时不用传，修改时必填
    var pcID: String = "",
    // 前缀
    var prefix: String = "",
)

