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.NotNull;
import javax.validation.constraints.Size;

/**
 * 产品需求对象 pms_product_requirement
 *
 * @author otto
 * @date 2023-10-10
 */
@Data
@ApiModel("用户需求更新对象")
public class ProductUserReqUpdateVo {
    /**
     * 需求Id
     */
    @ApiModelProperty(value = "需求Id", required = true)
    @NotNull
    private Long id;
    /**
     * 标题
     */
    @ApiModelProperty(value = "标题")
    @Size(max = 50, message = "长度需要小于50")
    private String title;

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

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

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

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

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

    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.EDIT.getKey());
        record.setOperator(pmsProductRequirement.getUpdateBy());
        record.setOperatingTime(pmsProductRequirement.getUpdateTime());
        return record;
    }
}
