package com.cmvr.inspection.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.cmvr.common.annotation.Excel;
import com.cmvr.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

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

/**
 * 统一巡检结果，承载PPE、仪表读数和人工判断结果。
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("inspection_result")
@ApiModel(value = "InspectionResult", description = "PPE识别、仪表读数识别和人工复核共用的巡检结果")
public class InspectionResult extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.INPUT)
    @ApiModelProperty(value = "巡检结果主键", example = "8f3e1f3a2db84de2a84eebdf8951b86a")
    private String id;

    @Excel(name = "结果编码")
    @ApiModelProperty(value = "巡检结果业务编码", example = "IR20260723143000123ABCDE")
    private String resultCode;

    @ApiModelProperty(value = "结果幂等键，平台内部使用", hidden = true)
    private String dedupeKey;

    @ApiModelProperty(value = "巡检任务实例数据库ID", example = "task-instance-id")
    private String taskInstanceId;

    @ApiModelProperty(value = "工作流运行实例ID", example = "flow-instance-id")
    private String flowInstanceId;

    @ApiModelProperty(value = "巡检任务ID", example = "inspection-task-id")
    private String taskId;

    @ApiModelProperty(value = "检测项ID", example = "detection-item-id")
    private String itemId;

    @ApiModelProperty(value = "工作流节点ID", example = "meter-node-1")
    private String nodeId;

    @ApiModelProperty(value = "工作流节点名称", example = "1号压力表读数识别")
    private String nodeName;

    @ApiModelProperty(value = "循环节点迭代路径JSON；非循环节点通常为[]", example = "[1,2]")
    private String iterationPath;

    @Excel(name = "结果类型")
    @ApiModelProperty(value = "结果类型", allowableValues = "PPE,METER,MANUAL", example = "METER")
    private String resultType;

    @Excel(name = "结果状态")
    @ApiModelProperty(value = "结果状态", allowableValues = "PENDING,NORMAL,ABNORMAL,RECOGNIZE_FAILED", example = "ABNORMAL")
    private String resultStatus;

    @Excel(name = "检查名称")
    @ApiModelProperty(value = "检查项显示名称", example = "1号压力表")
    private String resultName;

    @Excel(name = "数值")
    @ApiModelProperty(value = "结构化仪表读数；PPE和人工结果通常为空", example = "1.72")
    private BigDecimal valueNumber;

    @Excel(name = "结果内容")
    @ApiModelProperty(value = "文本结果或原始识别值", example = "1.72")
    private String valueText;

    @Excel(name = "单位")
    @ApiModelProperty(value = "仪表读数单位", example = "MPa")
    private String unit;

    @Excel(name = "告警级别")
    @ApiModelProperty(value = "最终命中的最高告警级别：1提示、2警告、3严重", allowableValues = "1,2,3", example = "2")
    private Integer alarmLevel;

    @ApiModelProperty(value = "告警描述", example = "压力过高")
    private String alarmMessage;

    @ApiModelProperty(value = "模型置信度，范围0到1", example = "0.96")
    private BigDecimal confidence;

    @ApiModelProperty(value = "PPE边缘事件event_id", example = "event-abc")
    private String sourceEventId;

    @ApiModelProperty(value = "主要证据的永久MinIO地址")
    private String evidenceUrl;

    @ApiModelProperty(value = "主要证据类型，与evidenceUrl同时写入",
            allowableValues = "IMAGE,VIDEO", example = "IMAGE")
    private String evidenceType;

    @ApiModelProperty(value = "模型或边缘端原始返回内容")
    private String rawResult;

    @ApiModelProperty(value = "最终命中的告警规则JSON快照")
    private String matchedRuleJson;

    @ApiModelProperty(value = "本次执行使用的全部告警规则JSON快照")
    private String ruleSnapshotJson;

    @ApiModelProperty(value = "人工复核账号", example = "admin")
    private String reviewer;

    @ApiModelProperty(value = "人工复核时间")
    private Date reviewTime;

    @ApiModelProperty(value = "人工复核说明")
    private String reviewRemark;

    @ApiModelProperty(value = "人工复核乐观锁版本，首次复核前为0", example = "0")
    private Integer reviewVersion;

    @ApiModelProperty(value = "异常结果关联的巡检告警ID")
    private String alarmId;

    @Excel(name = "检测时间", dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "结果发生时间")
    private Date occurredTime;
}
