package com.cr.map

import com.cr.common.CrUnitManager
import com.cr.pages.FragmentMap

/**
 * 操作系统：MAC系统
 * 创建者：王成
 * 创建日期：2023/6/12 16:46
 * 描述：案件模型
 */
class CaseModel {
    var name: String? = null  // define: 2023/6/12 案件名称
    var longitude: Double? = 0.0 // define: 2023/6/12 案件经度
    var latitude: Double? = 0.0 // define: 2023/6/12 案件纬度
    var altitude: Double? = 0.0 // define: 2023/6/12 案件高度
    var angle: Double? = 0.0 // define: 2023/6/12 案件角度
    var imgName: String? = "" // define: 2023/6/12 案件照片字符串
    var date: String? = "" // define: 2023/6/12 创建日期
    var isDown: Boolean? = false  // define: 2023/6/12 是否已下载
    var imgArray: MutableList<String>? = null // define: 2023/6/12 照片数组
    var caseType: CaseType? = CaseType.Non // define: 2023/6/12 案件点类型
    var joinPolygon: CaseLocalPolygonModel? = null // define: 2023/6/12 关联的案件图斑
    var isCheck: Boolean? = false // define: 2023/6/12 是否已选中
    var joinNetCaseAJHArray: MutableList<String>? = null // define: 2023/6/12 关联的网络案件号数组

    /**
     * 默认初始化
     * @constructor
     */
    constructor(){
        this.name = CrUnitManager.toSystemDate()
        this.imgName = ""
        this.longitude = 0.0
        this.latitude = 0.0
        this.altitude = 0.0
        this.angle = 0.0
        this.isDown = false
        this.isCheck = false
        this.caseType = CaseType.Non
        this.joinPolygon = CaseLocalPolygonModel()
        this.joinNetCaseAJHArray = mutableListOf()
        this.imgArray = mutableListOf()
        this.date = CrUnitManager.toSystemYMDHMSDate()
    }

    /**
     * 通过参数初始化
     * @param longitude Double 经度
     * @param latitude Double 纬度
     * @param altitude Double 高度
     * @param angle Double 角度
     * @param caseType CaseType 类型
     * @constructor
     */
    constructor(longitude:Double,latitude:Double,altitude:Double,angle:Double,caseType:CaseType):this(){
        this.longitude = longitude
        this.latitude = latitude
        this.altitude = altitude
        this.angle = angle
        this.caseType = caseType
    }

    /**
     * 通过属性初始化
     * @param attribute MutableMap<String,Any>
     * @constructor
     */
    constructor(attribute:MutableMap<String,Any>):this(){
        this.name = attribute[FragmentMap.FIELD_CASE_NAME].toString()
        this.imgName = attribute[FragmentMap.FIELD_CASE_IMAGES].toString()
        this.date = attribute[FragmentMap.FIELD_CASE_RQ].toString()
        this.isDown = attribute[FragmentMap.FIELD_CASE_ISDOWN].toString() == "1"
        this.longitude = attribute[FragmentMap.FIELD_CASE_LNG].toString().toDouble()
        this.latitude = attribute[FragmentMap.FIELD_CASE_LAT].toString().toDouble()
        this.altitude = attribute[FragmentMap.FIELD_CASE_ALT].toString().toDouble()
        this.angle = attribute[FragmentMap.FIELD_CASE_ANG].toString().toDouble()
        var mediaType = attribute[FragmentMap.FIELD_CASE_TYPE].toString()
        mediaType?.let {
            when (it) {
                FragmentMap.MEDIA_TYPE_WJ_NO -> {
                    this.caseType = CaseType.MediaTypeWjNo
                }
                FragmentMap.MEDIA_TYPE_WJ_YES -> {
                    this.caseType = CaseType.MediaTypeWjYes
                }
                FragmentMap.MEDIA_TYPE_REPEAT_NO -> {
                    this.caseType = CaseType.MediaTypeRepeatFlightNo
                }
                FragmentMap.MEDIA_TYPE_REPEAT_YES -> {
                    this.caseType = CaseType.MediaTypeRepeatFlightYes
                }
                else -> {
                    this.caseType = CaseType.Non
                }
            }
        }
    }

    /**
     * 赋值属性
     * @param attributes MutableMap<String, Any>
     */
    fun setAttributes(attributes:MutableMap<String,Any>){
        attributes!!.let {
            it[FragmentMap.FIELD_CASE_NAME] = this.name!!
            it[FragmentMap.FIELD_CASE_LNG] = this.longitude!!.toString()
            it[FragmentMap.FIELD_CASE_LAT] = this.latitude!!.toString()
            it[FragmentMap.FIELD_CASE_ALT] = this.altitude!!.toString()
            it[FragmentMap.FIELD_CASE_ANG] = this.angle!!.toString()
            it[FragmentMap.FIELD_CASE_ISDOWN] = if (this.isDown == true) "1" else "0"
            it[FragmentMap.FIELD_CASE_RQ] = this.date!!
            it[FragmentMap.FIELD_CASE_IMAGES] = this.imgName!!
            when(this.caseType){
                CaseType.MediaTypeWjNo->{
                    it[FragmentMap.FIELD_CASE_ISUP] = FragmentMap.MEDIA_TYPE_WJ_NO
                }
                CaseType.MediaTypeWjYes->{
                    it[FragmentMap.FIELD_CASE_ISUP] = FragmentMap.MEDIA_TYPE_WJ_YES
                }
                CaseType.MediaTypeRepeatFlightNo->{
                    it[FragmentMap.FIELD_CASE_ISUP] = FragmentMap.MEDIA_TYPE_REPEAT_NO
                }
                CaseType.MediaTypeRepeatFlightYes->{
                    it[FragmentMap.FIELD_CASE_ISUP] = FragmentMap.MEDIA_TYPE_REPEAT_YES
                }
            }
        }
    }

    /**
     * 获取案件点的字符串表示
     * @return String
     */
    fun getMediaTypeString():String{
        when(this.caseType){
            CaseType.MediaTypeWjNo->{
                return FragmentMap.MEDIA_TYPE_WJ_NO
            }
            CaseType.MediaTypeWjYes->{
                return FragmentMap.MEDIA_TYPE_WJ_YES
            }
            CaseType.MediaTypeRepeatFlightNo->{
                return FragmentMap.MEDIA_TYPE_REPEAT_NO
            }
            CaseType.MediaTypeRepeatFlightYes->{
                return FragmentMap.MEDIA_TYPE_REPEAT_YES
            }
        }
        return ""
    }

    /**
     * 根据案件点类型的字符串表示获取枚举表示
     * @param typeString String 类型字符串
     * @return CaseType 类型
     */
    fun getMediaType(typeString:String):CaseType{
        return when (typeString) {
            FragmentMap.MEDIA_TYPE_WJ_NO -> {
                CaseType.MediaTypeWjNo
            }
            FragmentMap.MEDIA_TYPE_WJ_YES -> {
                CaseType.MediaTypeWjYes
            }
            FragmentMap.MEDIA_TYPE_REPEAT_NO -> {
                CaseType.MediaTypeRepeatFlightNo
            }
            FragmentMap.MEDIA_TYPE_REPEAT_YES -> {
                CaseType.MediaTypeRepeatFlightYes
            }
            else -> CaseType.Non
        }
    }
}