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

import com.alibaba.fastjson2.JSONObject;
import com.microservices.pms.product.domain.PmsProductReqOperationRecord;
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 java.util.Date;

/**
 * 产品需求对象 pms_product_requirement
 *
 * @author otto
 * @date 2023-10-10
 */
@Data
@ApiModel("需求评审对象")
public class ProductReqReviewVo {

    @ApiModelProperty(value = "需求Id", required = true)
    @NotNull
    private Long id;

    @ApiModelProperty(value = "评审状态", required = true)
    @NotNull
    private String reviewStatus;

    @ApiModelProperty(value = "评审时间（前端默认取当前时间）", required = true)
    @NotNull
    private Date reviewTime;

    @ApiModelProperty(value = "评审人", required = true)
    @NotNull
    private String reviewUser;

    @ApiModelProperty(value = "评审意见", required = true)
    @NotNull
    private String reviewContent;

    public PmsProductReqOperationRecord toUserReqRecord(String operator) {
        PmsProductReqOperationRecord record = toRecord(operator);
        record.setType(ProductReqOperationType.REVIEW_USER_REQ.getKey());
        return record;
    }

    public PmsProductReqOperationRecord toReqSpecsRecord(String operator) {
        PmsProductReqOperationRecord record = toRecord(operator);
        record.setType(ProductReqOperationType.REVIEW_REQ_SPECS.getKey());
        return record;
    }

    private PmsProductReqOperationRecord toRecord(String operator) {
        PmsProductReqOperationRecord record = new PmsProductReqOperationRecord();
        record.setProductRequirementId(id);
        record.setOperation(reviewStatus);
        record.setOperator(operator);
        record.setOperatingTime(reviewTime);
        JSONObject contentJson = new JSONObject();
        contentJson.put("reviewUser", reviewUser);
        contentJson.put("reviewContent", reviewContent);
        record.setContent(contentJson.toJSONString());
        return record;
    }
}
