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

import com.microservices.common.core.utils.bean.BeanUtils;
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.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * 用户需求输入对象
 *
 * @author otto
 * @date 2023-10-10
 */
@Data
@ApiModel("需求规格输入对象")
public class ProductReqSpecsInputVo {
    @ApiModelProperty(value = "标题", required = true)
    @NotBlank
    @Size(max = 200, message = "长度需要小于200")
    private String title;

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

    @ApiModelProperty(value = "关联产品标识", required = true)
    @NotNull
    private String pmsProductIdentifier;

    @ApiModelProperty(value = "正文", required = true)
    @NotBlank
    private String content;

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

    @ApiModelProperty(value = "企业标识", hidden = true)
    private String enterpriseIdentifier;

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

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


    public PmsProductRequirement toPmsProductRequirement() {
        PmsProductRequirement target = new PmsProductRequirement();
        BeanUtils.copyProperties(this, target);
        return target;
    }

    public PmsProductReqOperationRecord toPmsProductReqOperationRecord(PmsProductRequirement pmsProductRequirement) {
        PmsProductReqOperationRecord record = new PmsProductReqOperationRecord();
        record.setProductRequirementId(pmsProductRequirement.getId());
        record.setType(ProductReqOperationType.CONTENT_MODIFY.getKey());
        record.setOperation(ProductContentModifyOperation.CREATE.getKey());
        record.setOperator(pmsProductRequirement.getCreateBy());
        record.setOperatingTime(pmsProductRequirement.getCreateTime());
        return record;
    }
}
