package com.yzx.ebrand.model

import kotlin.math.abs

data class Visitor(
    val add_time: Int = 0,
    val auditRecordOuts: MutableList<AuditRecordOut> = mutableListOf(),
    val audit_status: Int = 0,
    val car_in_time: Int = 0,
    val car_out_time: Int = 0,
    val card_no: String = "",
    val end_time: Int = 0,
    val face_identity: String = "",
    val face_key: String = "",
    val health_code_identity: String = "",
    val health_code_key: String = "",
    val health_code_status: Int = -1,
    val history_num: Int = 0,
    val id: Int = 0,
    val in_out_num: Int = 0,
    val is_drive: Int = 0,
    val license_plate: String = "",
    val positionNums: List<Any> = mutableListOf(),
    val position_id: Int = 0,
    val reception_user: String = "",
    val reception_user_id: Int = 0,
    val start_time: Int = 0,
    val trip_code_identity: String = "",
    val trip_code_key: String = "",
    val user_id: Int = 0,
    val user_name: String = "",
    val user_phone: String = "",
    val user_type: Int = 0,
    val visit_reason: String = "",
    val nuclein_file_key: String = "",
    val nuclein_file_identity: String = "",
    val nuclein_time: Int = 0,
    val nuclein_result: Int = 0
) {
    fun getStatusImg(): String {
        return when (audit_status) {
            0 -> "https://oa-edu-1259243469.cos.ap-chengdu.myqcloud.com/public/v_status_0.png"
            1 -> "https://oa-edu-1259243469.cos.ap-chengdu.myqcloud.com/public/v_status_1.png"
            2 -> "https://oa-edu-1259243469.cos.ap-chengdu.myqcloud.com/public/v_status_2.png"
            -1 -> "https://oa-edu-1259243469.cos.ap-chengdu.myqcloud.com/public/v_status_-1.png"
            else -> "--"
        }
    }

    fun getStep(): MutableList<AuditRecordOut> {
        val list = mutableListOf<AuditRecordOut>()
        list.add(AuditRecordOut(add_time = add_time, typeTxt = "发起申请"))
        auditRecordOuts.forEach {
            list.add(it.getCopyItem())
        }
        return list
    }

    fun getNucleinStatusObj(): NucleinStatusObj {
        val time = abs(add_time - nuclein_time)
        val nucleinResultName = if (nuclein_result == 2) {
            "阳性"
        } else {
            "阴性"
        }
        var name = ""
        var color = "#5DAD64"
        when {
            time < 24 * 60 * 60 -> {
                name = "省内24小时：${nucleinResultName}"
                color = "#5DAD64";
            }
            time < 48 * 60 * 60 -> {
                name = "省内48小时：${nucleinResultName}"
                color = "#3c7ef6";
            }
            time < 72 * 60 * 60 -> {
                name = "省内72小时：${nucleinResultName}"
                color = "#62D5FF";
            }
            else -> {
                name = "省内72小时以上：${nucleinResultName}"
                color = "#999999";
            }
        }
        if (nuclein_result == 2) {
            color = "#ff4040"
        }
        return NucleinStatusObj(name, color)
    }
}

data class NucleinStatusObj(val nuclein_name: String = "",
                            val nuclein_color: String = "#333333")
data class AuditRecordOut(
    val add_time: Int = 0,
    val audit_remark: String = "",
    val audit_status: Int = 0,
    val audit_user_name: String = "",
    val typeTxt: String = "",
    val id: Int = 0
) {
    fun getTitle(): String {
        if (typeTxt.isNotEmpty()) {
            return typeTxt
        }
        return "接待人审批"
    }

    fun getCopyItem(): AuditRecordOut {
        return AuditRecordOut(add_time, audit_remark, audit_status, audit_user_name, typeTxt, id)
    }
}