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 lombok.Data;

import javax.persistence.Column;
import javax.swing.text.StyleConstants;
import java.util.Date;

/**
 * @Author suzhuhong
 * @Date 2024/6/25 11:19
 * @Version 1.0
 */
@Data
public class DecorationDesignRequest {

    @Column(name = "shop_id")
    private Long shopId;

    /**
     * 报价单
     */
    @Column(name = "quotation_url")
    private String quotationUrl;

    /**
     * 设计图
     */
    @Column(name = "design_url")
    private String designUrl;

    /**
     * 备注
     */
    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.setRemark(this.remark);
        decorationDesignInfoDO.setQuotationUrl(this.quotationUrl);
        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));
        }
        decorationDesignInfoDO.setUpdateTime(new Date());
        return decorationDesignInfoDO;
    }

}
