package com.microservices.pms.product.domain.vo;

import com.microservices.common.core.utils.StringUtils;
import com.microservices.pms.product.domain.PmsProductReqOperationRecord;
import com.microservices.pms.product.domain.PmsProductRequirement;
import com.microservices.pms.product.domain.enums.ProductContentModifyOperation;
import com.microservices.pms.product.domain.enums.ProductReqOperationType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * 产品需求对象 pms_product_requirement
 *
 * @author otto
 * @date 2023-10-10
 */
@Data
@ApiModel("变更需求规格变更对象")
public class ProductReqSpecsChangeVo {
    @ApiModelProperty(value = "需求Id", required = true)
    @NotNull
    private Long id;

    @ApiModelProperty(value = "标题")
    @Size(max = 50, message = "长度需要小于50")
    private String title;

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

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

    // 需求变更记录应记录在原需求下
    public PmsProductReqOperationRecord toReqSpecsChangeRecord(Long oldReqSpecsId, PmsProductRequirement changeReqSpecs) {
        PmsProductReqOperationRecord record = new PmsProductReqOperationRecord();
        record.setProductRequirementId(oldReqSpecsId);
        record.setType(ProductReqOperationType.CONTENT_MODIFY.getKey());
        record.setOperation(ProductContentModifyOperation.CHANGING_REQ.getKey());
        record.setOperator(changeReqSpecs.getUpdateBy());
        record.setOperatingTime(changeReqSpecs.getUpdateTime());
        return record;
    }

    public boolean isReqChange(PmsProductRequirement oldPmsProductRequirement) {

        if (this.getContent() != null && !this.content.equals(oldPmsProductRequirement.getContent())) {
            return true;
        }
        if (StringUtils.isNotEmpty(this.getTitle()) && !this.title.equals(oldPmsProductRequirement.getTitle())) {
            return true;
        }
        return this.getFileIdentifiers() != null && !this.getFileIdentifiers().equals(oldPmsProductRequirement.getFileIdentifiers());
    }
}
