package com.microservices.pms.product.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.microservices.common.core.utils.StringUtils;
import com.microservices.common.core.utils.bean.BeanUtils;
import com.microservices.common.core.web.domain.BaseEntity;
import com.microservices.pms.product.domain.enums.ProductReqStatus;
import com.microservices.pms.product.domain.vo.PmsProductRequirementDataVo;
import com.microservices.pms.product.domain.vo.ProductReqSpecsChangeVo;
import com.microservices.pms.product.domain.vo.ProductReqSpecsDataVo;
import com.microservices.pms.product.domain.vo.ProductUserReqDataVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;
import java.util.List;

/**
 * 产品需求对象 pms_product_requirement
 * 
 * @author otto
 * @date 2023-10-10
 */
@Data
@ApiModel("产品需求对象")
public class PmsProductRequirement extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 需求ID */
    private Long id;

    /** 索引 */
    @ApiModelProperty(value = "索引")
    private Long index;

    /** 标题 */
    @ApiModelProperty(value = "标题")
    private String title;

    @ApiModelProperty(value = "产品需求状态")
    private String status;

    /** 关联优先级ID */
    @ApiModelProperty(value = "关联优先级ID")
    private Long priorityId;

    /** 关联产品模块ID */
    @ApiModelProperty(value = "关联产品模块ID")
    private Long pmsProductModuleId;

    /** 关联产品计划ID */
    @ApiModelProperty(value = "关联产品计划ID")
    private Long pmsProductPlanId;

    /** 关联产品标识 */
    @ApiModelProperty(value = "关联产品标识")
    private String pmsProductIdentifier;

    /** 正文 */
    @ApiModelProperty(value = "正文")
    private String content;

    /** 标记 */
    @ApiModelProperty(value = "标记")
    private String tagIds;

    /**
     * 标记Id
     */
    @ApiModelProperty(value = "标记Id")
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private String tagId;

    /** 标记名称，使用逗号分割的字符 */
    @ApiModelProperty(value = "标记名称，使用逗号分割的字符")
    private String tags;

    /** 开始时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "开始时间")
    private Date startTime;

    /** 结束时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "结束时间")
    private Date endTime;

    /**
     * 附件标识列表
     */
    @ApiModelProperty(value = "附件标识列表")
    private String fileIdentifiers;

    /** 排序 */
    @ApiModelProperty(value = "排序")
    private Integer sort;

    /** 删除标志（0代表存在 2代表删除） */
    private String delFlag;

    /**
     * 需求负责人Gitlink ID列表（逗号分隔）
     */
    @ApiModelProperty(value = "需求负责人Gitlink ID列表（逗号分隔）")
    private String requirementAssigneeGitlinkIds;

    /**
     * 需求负责人Gitlink ID
     */
    @ApiModelProperty(value = "需求负责人Gitlink ID")
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private String requirementAssigneeGitlinkId;

    /** 关联项目ID */
    @ApiModelProperty(value = "关联项目ID")
    private Long pmsProjectId;

    /** 关联项目ID */
    @ApiModelProperty(value = "关联模块ID")
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<Long> childrenModuleIdList;


    @ApiModelProperty(value = "产品标识集合查询")
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<String> productIdentifierList;

    /**
     * 原需求id
     */
    @ApiModelProperty(value = "原需求id")
    private Long fromId;
    /**
     * 原需求id
     */
    @ApiModelProperty(value = "关联项目需求id")
    private Long projectReqId;

    @ApiModelProperty(value = "产品需求类型")
    private String type;

    @ApiModelProperty(value = "需求来源用户")
    private String sourceUser;

    @ApiModelProperty(value = "需求来源单位")
    private String sourceCompany;

    @ApiModelProperty(value = "需求标识")
    private String identifier;

    @ApiModelProperty(value = "评审时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date reviewTime;

    @ApiModelProperty(value = "评审内容")
    private String reviewContent;

    public PmsProductRequirementDataVo toPmsProductRequirementDataVo(){
        PmsProductRequirementDataVo target = new PmsProductRequirementDataVo();
        BeanUtils.copyProperties(this, target);
        return target;
    }

    public ProductUserReqDataVo toProductUserReqDataVo() {
        ProductUserReqDataVo target = new ProductUserReqDataVo();
        BeanUtils.copyProperties(this, target);
        return target;
    }

    public ProductReqSpecsDataVo toProductReqSpecsDataVo() {
        ProductReqSpecsDataVo target = new ProductReqSpecsDataVo();
        BeanUtils.copyProperties(this, target);
        return target;
    }

    public PmsProductRequirement userReqToReqSpecs() {
        PmsProductRequirement target = new PmsProductRequirement();
        BeanUtils.copyProperties(this, target);
        target.setId(null);
        target.setFromId(this.id);
        target.setStatus(ProductReqStatus.REVIEWED_REQ_SPECS.getKey());
        return target;
    }

    public PmsProductRequirement toChangeReqSpecs(ProductReqSpecsChangeVo productReqSpecsChangeVo) {
        PmsProductRequirement target = new PmsProductRequirement();
        BeanUtils.copyProperties(this, target);
        target.setId(null);
        target.setFromId(this.id);
        target.setStatus(ProductReqStatus.CHANGING_REQ_SPECS.getKey());
        if (StringUtils.isNotEmpty(productReqSpecsChangeVo.getTitle())) {
            target.setTitle(productReqSpecsChangeVo.getTitle());
        }
        if (StringUtils.isNotEmpty(productReqSpecsChangeVo.getContent())) {
            target.setContent(productReqSpecsChangeVo.getContent());
        }
        if (StringUtils.isNotEmpty(productReqSpecsChangeVo.getFileIdentifiers())) {
            target.setFileIdentifiers(productReqSpecsChangeVo.getFileIdentifiers());
        }
        return target;
    }
}
