package com.cool.store.request;

import com.alibaba.fastjson.JSONObject;
import com.cool.store.constants.CommonConstants;
import com.cool.store.dto.decoration.ThreeAcceptanceDTO;
import com.cool.store.entity.DecorationDesignInfoDO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Column;
import java.util.Date;

/**
 * @Author suzhuhong
 * @Date 2024/6/25 11:19
 * @Version 1.0
 */
@Data
@ApiModel("设计阶段保存入参")
public class DecorationDesignRequest {

    @ApiModelProperty("店铺ID")
    private Long shopId;

    @ApiModelProperty(value = "设计派单ID")
    private String designSheetId;

    @ApiModelProperty("设计组长ID")
    private String designLeaderId;

    @ApiModelProperty("设计师ID")
    private String designUserId;

    @ApiModelProperty(value = "报价单ID(报价单编号)")
    private String quotationSheetId;

    @ApiModelProperty("报价员ID")
    private String quotationUserId;

    @ApiModelProperty("报价单URL")
    private String quotationUrl;

    @ApiModelProperty("设计图URL")
    private String designUrl;

    @ApiModelProperty("报价备注")
    private String quotationRemark;

    @ApiModelProperty("设计备注")
    private String remark;

    /**
     * 加密商验收签名  {"pic":"","acceptanceTime":"","result":"","remark":"","status":0}
     */
    @Column(name = "partner_acceptance_signatures")
    private ThreeAcceptanceDTO partnerAcceptanceSignatures;


    public DecorationDesignInfoDO toDecorationDesignInfoDO() {
        DecorationDesignInfoDO decorationDesignInfoDO = new DecorationDesignInfoDO();
        decorationDesignInfoDO.setDesignUrl(this.designUrl);
        decorationDesignInfoDO.setShopId(this.shopId);
        decorationDesignInfoDO.setDesignSheetId(this.designSheetId);
        decorationDesignInfoDO.setQuotationSheetId(this.quotationSheetId);
        if (this.designLeaderId != null) {
            decorationDesignInfoDO.setDesignLeaderId(this.designLeaderId);
        }
        if (this.designUserId != null) {
            decorationDesignInfoDO.setDesignUserId(this.designUserId);
        }
        if (this.quotationUserId != null) {
            decorationDesignInfoDO.setQuotationUserId(this.quotationUserId);
        }
        if (this.quotationRemark != null) {
            decorationDesignInfoDO.setQuotationRemark(this.quotationRemark);
        }
        if (this.quotationUrl != null) {
            decorationDesignInfoDO.setQuotationUrl(this.quotationUrl);
        }
        decorationDesignInfoDO.setRemark(this.remark);

        if (this.partnerAcceptanceSignatures != null) {
            ThreeAcceptanceDTO threeAcceptanceDTO = this.partnerAcceptanceSignatures;
            threeAcceptanceDTO.setAcceptanceTime(new Date());
            threeAcceptanceDTO.setStatus(CommonConstants.ONE);
            threeAcceptanceDTO.setResult(CommonConstants.ONE);
            threeAcceptanceDTO.setRemark(threeAcceptanceDTO.getRemark() == null ? "" : threeAcceptanceDTO.getRemark());
            decorationDesignInfoDO.setPartnerAcceptanceSignatures(JSONObject.toJSONString(threeAcceptanceDTO));
        }
        return decorationDesignInfoDO;
    }

}
