package com.cool.store.request;

import com.cool.store.entity.LinePayDO;
import com.cool.store.enums.ClaimStatusEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.tika.utils.DateUtils;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

import static com.cool.store.enums.WorkflowSubStageStatusEnum.PAY_DEPOSIT_50;

@Data
public class LinePaySubmitRequest {

    private Long id;

    @ApiModelProperty("xfsg_user_info.partner_id")
    private String partnerId;

    @ApiModelProperty("line_info.id")
    private Long lineId;

    @ApiModelProperty("支付状态 45:待缴费 50:已缴费 55缴费失败")
    private Integer payStatus;

    @ApiModelProperty("支付方式 1微信 2银行转账,3-线上支付,4-线下支持")
    private Integer payType;

    @ApiModelProperty("付款人姓名/加盟商姓名")
    private String payUserName;

    @ApiModelProperty("付款账号")
    private String payAccount;

    @ApiModelProperty("开户行code")
    private String bankCode;

    @ApiModelProperty("开户行名称")
    private String bankName;

    @ApiModelProperty("支行code")
    private String branchBankCode;

    @ApiModelProperty("支行名称")
    private String branchBankName;

    @ApiModelProperty("缴纳时间")
    private String payTime;

    @ApiModelProperty("付款截图")
    private String payPic;

    @ApiModelProperty("承诺书图片")
    private String promisePic;

    @ApiModelProperty("支付类型  1-缴纳加盟费")
    private Integer payBusinessType;
    @ApiModelProperty("铺位id")
    private Long shopId;
    @ApiModelProperty("缴费金额")
    private BigDecimal amount;
    //废弃
    @ApiModelProperty("组合字段：缴费时间+付款截图，数组")
    private String combinedField;

    @ApiModelProperty("交易流水号")
    private String paySerialNumber;

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

    /**
     * @Auther: wangshuo
     * @Date: 2025/5/30
     * @description:加盟费使用
     */
    public static LinePayDO convertFranchiseFee(LinePaySubmitRequest request) {
        LinePayDO linePayDO = new LinePayDO();
        linePayDO.setId(request.getId());
        linePayDO.setPartnerId(request.getPartnerId());
        linePayDO.setShopId(request.getShopId());
        linePayDO.setLineId(request.getLineId());
        linePayDO.setPayStatus(PAY_DEPOSIT_50.getCode());
        linePayDO.setXgjClaimStatus(ClaimStatusEnum.TO_BE_CLAIMED.getCode());
        linePayDO.setPayType(request.getPayType());
        linePayDO.setPayUserName(request.getPayUserName());
        linePayDO.setPayAccount(request.getPayAccount());
        linePayDO.setBankCode(request.getBankCode());
        linePayDO.setBankName(request.getBankName());
        linePayDO.setBranchBankCode(request.getBranchBankCode());
        linePayDO.setBranchBankName(request.getBranchBankName());
        try {
            linePayDO.setPayTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(request.getPayTime()));
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        linePayDO.setPayPic(request.getPayPic());
        linePayDO.setPaySerialNumber(request.getPaySerialNumber());
        linePayDO.setAmount(request.getAmount());
        linePayDO.setPayBusinessType(request.getPayBusinessType());
        linePayDO.setXgjClaimStatus(0);
        linePayDO.setRemark(request.getRemark());
        linePayDO.setDeleted(false);
        return linePayDO;
    }
}
