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 ProductUserReqInputVo {
    /**
     * 标题
     */
    @ApiModelProperty(value = "标题", required = true)
    @NotBlank
    @Size(max = 200, message = "长度需要小于200")
    private String title;

    /**
     * 关联产品模块ID
     */
    @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 = "需求来源用户（需前端默认填充当前用户昵称）", required = true)
    @NotBlank
    private String sourceUser;

    @ApiModelProperty(value = "需求来源单位（需前端默认填充当前企业名称）", required = true)
    @NotBlank
    private String sourceCompany;

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


    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;
    }
}
