package com.ningdatech.pmapi.sys.model.vo;

import com.ningdatech.pmapi.projectlib.enumeration.InstTypeEnum;
import com.ningdatech.pmapi.projectlib.enumeration.WarningFlowTypeEnum;
import com.ningdatech.pmapi.projectlib.enumeration.WarningOperationTypeEnum;
import com.wflow.enums.WarningRuleTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 实体类
 * 角色分配
 * 预警触发通知记录
 * @author PoffyZhang
 */
@Data
@NoArgsConstructor
@ToString(callSuper = true)
@Accessors(chain = true)
@ApiModel(value = "WflowEarlyWarningRecords", description = "预警触发通知记录")
public class WflowEarlyWarningRecordsVO implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id")
    private Long id;

    /**
     * 区域CODE
     */
    @ApiModelProperty(value = "区域CODE")
    private String areaCode;

    /**
     * 项目名称
     */
    @ApiModelProperty(value = "项目名称")
    private String projectName;


    /**
     * 流程类型
     */
    @ApiModelProperty(value = "流程类型")
    private Integer instType;

    /**
     * 任务开始时间
     */
    @ApiModelProperty(value = "任务开始时间")
    private LocalDateTime instStart;

    /**
     * 预警时间
     */
    @ApiModelProperty(value = "预警时间")
    private LocalDateTime warningTime;

    /**
     * 通知人名
     */
    @ApiModelProperty(value = "通知人名")
    private String warningUsername;

    /**
     * 预警员工号
     */
    @ApiModelProperty(value = "预警员工号")
    private String warningEmployeecode;

    /**
     * 通知方式
     */
    @ApiModelProperty(value = "通知方式 0浙政钉 1短信 逗号分隔")
    private String noticeMethod;

    /**
     * 通知内容
     */
    @ApiModelProperty(value = "通知内容")
    private String noticeContent;

    /**
     * 申报单位
     */
    @ApiModelProperty(value = "申报单位CODE")
    private String buildOrgCode;
    @ApiModelProperty(value = "申报单位")
    private String buildOrgName;

    /**
     * 规则
     */
    @ApiModelProperty(value = "规则类型 1.流程预警规则 2.填报预警规则 3.实施监督")
    private Integer ruleType;


    private LocalDateTime createOn;
    private String createBy;
    private LocalDateTime updateOn;
    private String updateBy;

    public String getInstTypeName(){
        if(Objects.nonNull(this.instType) && Objects.nonNull(this.ruleType)){
            if(this.ruleType.equals(WarningRuleTypeEnum.PROCESS_WARNING.getCode())){
                InstTypeEnum instEnum = InstTypeEnum.getByCode(this.instType);
                if(Objects.nonNull(instEnum)){
                    return instEnum.getDesc();
                }
            }else if(this.ruleType.equals(WarningRuleTypeEnum.DECLARED_WARNING.getCode())){
                WarningFlowTypeEnum warningFlowTypeEnum = WarningFlowTypeEnum.getByCode(this.instType);
                if(Objects.nonNull(warningFlowTypeEnum)){
                    return warningFlowTypeEnum.getDesc();
                }
            }else if(this.ruleType.equals(WarningRuleTypeEnum.OPERATION_WARNING.getCode())){
                WarningOperationTypeEnum operationTypeEnum = WarningOperationTypeEnum.getByCode(this.instType);
                if(Objects.nonNull(operationTypeEnum)){
                    return operationTypeEnum.getDesc();
                }
            }
        }
        return StringUtils.EMPTY;
    }

    public String getRuleTypeName(){
        if(Objects.nonNull(this.ruleType)){
            WarningRuleTypeEnum warningEnum = WarningRuleTypeEnum.checkByCode(this.instType);
            if(Objects.nonNull(warningEnum)){
                return warningEnum.getDesc();
            }
        }
        return StringUtils.EMPTY;
    }
}
