package com.uavps.system.domain;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.uavps.common.annotation.Excel;
import com.uavps.common.core.domain.BaseEntity;
import com.uavps.system.domain.dto.CustomizedMultiTargetFormationDTO;
import com.uavps.system.domain.dto.FixedMultiTargetFormationDTO;
import com.uavps.system.domain.dto.PlatformUavDTO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 任务数据对象 uavps_task
 * 
 * @author ruoyi
 * @date 2025-04-17
 */
public class UavpsTask extends BaseEntity
{
    private static final long serialVersionUID = 1L;


    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    public static final String START = "start";
    public static final String CHANGE = "change";
    public static final String DISAPPEAR = "disappear";
    public static final String SHOW = "show";
    public static final String END = "end";
    // 未开始
    public static final String NOT_STARTED = "0";
    // 进行中
    public static final String RUNNING = "1";
    // 已完成
    public static final String COMPLETED = "2";
    // 失败
    public static final String FAILED = "3";

    /** 业务ID */
    private Long bizId;

    /** 任务名称 */
    @Excel(name = "任务名称")
    private String bizName;

    /** 业务类型 */
    private String bizType;

    /** 多目标类型 */
    private String multiTarget;

    /** 噪声类型 */
    private String noiseType;

    /** 噪声方差 */
    private BigDecimal noiseVariance;

    /** 噪声均值 */
    private BigDecimal noiseMean;

    /** 固定翼平台无人机数据 */
    @JsonIgnore
    private String platformUavStr;

    /** 固定编队目标数据 */
    @JsonIgnore
    private String fixedMultiTargetFormationStr;

    /** 自定义编队目标数据 */
    @JsonIgnore
    private String customizedMultiTargetFormationStr;

    /** 状态 */
    @Excel(name = "状态")
    private String status;

    /** 开始时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date startTime;

    /** 结束时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "结束时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date endTime;

    /** 噪声数据文件路径 */
    private String filePath;

    /** 固定翼平台无人机数据 */
    private PlatformUavDTO platformUav;

    /** 固定编队目标数据 */
    private FixedMultiTargetFormationDTO fixedMultiTargetFormation;

    /** 自定义编队目标数据 */
    private List<CustomizedMultiTargetFormationDTO> customizedMultiTargetFormation;

    private List<Integer> numbers = new ArrayList<>();

    public void setBizId(Long bizId) 
    {
        this.bizId = bizId;
    }

    public Long getBizId() 
    {
        return bizId;
    }
    public void setBizName(String bizName) 
    {
        this.bizName = bizName;
    }

    public String getBizName() 
    {
        return bizName;
    }
    public void setBizType(String bizType) 
    {
        this.bizType = bizType;
    }

    public String getBizType() 
    {
        return bizType;
    }
    public void setMultiTarget(String multiTarget) 
    {
        this.multiTarget = multiTarget;
    }

    public String getMultiTarget() 
    {
        return multiTarget;
    }
    public void setNoiseType(String noiseType)
    {
        this.noiseType = noiseType;
    }

    public String getNoiseType()
    {
        return noiseType;
    }
    public void setNoiseVariance(BigDecimal noiseVariance)
    {
        this.noiseVariance = noiseVariance;
    }

    public BigDecimal getNoiseVariance()
    {
        return noiseVariance;
    }
    public void setNoiseMean(BigDecimal noiseMean)
    {
        this.noiseMean = noiseMean;
    }

    public BigDecimal getNoiseMean()
    {
        return noiseMean;
    }
    public void setPlatformUavStr(String platformUavStr) 
    {
        this.platformUavStr = platformUavStr;
    }

    public String getPlatformUavStr() 
    {
        return platformUavStr;
    }
    public void setFixedMultiTargetFormationStr(String fixedMultiTargetFormationStr) 
    {
        this.fixedMultiTargetFormationStr = fixedMultiTargetFormationStr;
    }

    public String getFixedMultiTargetFormationStr() 
    {
        return fixedMultiTargetFormationStr;
    }
    public void setCustomizedMultiTargetFormationStr(String customizedMultiTargetFormationStr) 
    {
        this.customizedMultiTargetFormationStr = customizedMultiTargetFormationStr;
    }

    public String getCustomizedMultiTargetFormationStr() 
    {
        return customizedMultiTargetFormationStr;
    }
    public void setStatus(String status) 
    {
        this.status = status;
    }

    public String getStatus() 
    {
        return status;
    }
    public void setStartTime(Date startTime)
    {
        this.startTime = startTime;
    }

    public Date getStartTime() 
    {
        return startTime;
    }
    public void setEndTime(Date endTime) 
    {
        this.endTime = endTime;
    }

    public Date getEndTime() 
    {
        return endTime;
    }
    public void setFilePath(String filePath) 
    {
        this.filePath = filePath;
    }

    public String getFilePath() 
    {
        return filePath;
    }


    public PlatformUavDTO getPlatformUav() {
        if (platformUav == null && StringUtils.isNotEmpty(platformUavStr)) {
            ObjectMapper mapper = new ObjectMapper();
            try {
                this.platformUav = mapper.readValue(this.platformUavStr, PlatformUavDTO.class);
            } catch (Exception e) {
                logger.error("UavpsTask.getPlatformUav error", e);
            }
        }
        return platformUav;
    }

    public void setPlatformUav(PlatformUavDTO platformUav) {
        this.platformUav = platformUav;
        if (platformUav != null && StringUtils.isEmpty(this.platformUavStr)) {
            ObjectMapper mapper = new ObjectMapper();
            try {
                String json = mapper.writeValueAsString(platformUav);
                this.platformUavStr = json;
            } catch (Exception e) {
                logger.error("UavpsTask.setPlatformUav error", e);
            }
        }
    }

    public FixedMultiTargetFormationDTO getFixedMultiTargetFormation() {
        if (fixedMultiTargetFormation == null && StringUtils.isNotEmpty(fixedMultiTargetFormationStr)) {
            ObjectMapper mapper = new ObjectMapper();
            try {
                fixedMultiTargetFormation = mapper.readValue(this.fixedMultiTargetFormationStr, FixedMultiTargetFormationDTO.class);
            } catch (Exception e) {
                logger.error("UavpsTask.getPlatformUav error", e);
            }
        }
        return fixedMultiTargetFormation;
    }

    public void setFixedMultiTargetFormation(FixedMultiTargetFormationDTO fixedMultiTargetFormation) {
        this.fixedMultiTargetFormation = fixedMultiTargetFormation;
        if (fixedMultiTargetFormation != null && StringUtils.isEmpty(this.fixedMultiTargetFormationStr)) {
            ObjectMapper mapper = new ObjectMapper();
            String json = null;
            try {
                json = mapper.writeValueAsString(fixedMultiTargetFormation);
            } catch (Exception e) {
                logger.error("UavpsTask.setPlatformUav error", e);
            }
            this.fixedMultiTargetFormationStr = json;
        }
    }

    public List<CustomizedMultiTargetFormationDTO> getCustomizedMultiTargetFormation() {
        if (customizedMultiTargetFormation == null && StringUtils.isNotEmpty(customizedMultiTargetFormationStr)) {
            ObjectMapper mapper = new ObjectMapper();
            try {
                this.customizedMultiTargetFormation = mapper.readValue(customizedMultiTargetFormationStr, new TypeReference<List<CustomizedMultiTargetFormationDTO>>() {});
            } catch (Exception e) {
                logger.error("UavpsTask.getCustomizedMultiTargetFormation error", e);
            }
        }
        return customizedMultiTargetFormation;
    }

    public void setCustomizedMultiTargetFormation(List<CustomizedMultiTargetFormationDTO> customizedMultiTargetFormation) {
        this.customizedMultiTargetFormation = customizedMultiTargetFormation;
        if (customizedMultiTargetFormation != null && StringUtils.isEmpty(this.customizedMultiTargetFormationStr)) {
            ObjectMapper mapper = new ObjectMapper();
            try {
                customizedMultiTargetFormationStr = mapper.writeValueAsString(customizedMultiTargetFormation);
            } catch (Exception e) {
                logger.error("UavpsTask.setCustomizedMultiTargetFormation error", e);
            }
        }
    }

    public List<Integer> getNumbers() {
        return numbers;
    }

    public void setNumbers(List<Integer> numbers) {
        this.numbers = numbers;
    }

    public Long getTotalDuration() {
        if (COMPLETED.equals(this.status) && startTime != null && endTime != null) {
            return endTime.getTime() - startTime.getTime();
        } else {
            return null;
        }
    }

    @Override
    public String toString() {
        return "UavpsTask{" +
                "bizId=" + bizId +
                ", bizName='" + bizName + '\'' +
                ", bizType='" + bizType + '\'' +
                ", multiTarget='" + multiTarget + '\'' +
                ", noiseType='" + noiseType + '\'' +
                ", noiseVariance=" + noiseVariance +
                ", noiseMean=" + noiseMean +
                ", platformUavStr='" + platformUavStr + '\'' +
                ", fixedMultiTargetFormationStr='" + fixedMultiTargetFormationStr + '\'' +
                ", customizedMultiTargetFormationStr='" + customizedMultiTargetFormationStr + '\'' +
                ", status='" + status + '\'' +
                ", startTime=" + startTime +
                ", endTime=" + endTime +
                ", filePath='" + filePath + '\'' +
                ", platformUav=" + platformUav +
                ", fixedMultiTargetFormation=" + fixedMultiTargetFormation +
                ", customizedMultiTargetFormation=" + customizedMultiTargetFormation +
                ", numbers=" + numbers +
                '}';
    }
}
