package com.ruoyi.newwxpay.pay;

import com.ruoyi.common.utils.date.LocalDateTimeUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString(callSuper = true)
public class WxMinPayRequest {

    /***
     * 商户订单号
     */
    @NotBlank(message = "商户订单号不能为空")
    private String outTradeNo;

    /***
     * 订单金额
     */
    @NotNull(message = "订单金额不能为空")
    private BigDecimal money;

    /***
     * 用户openid
     */
    @NotBlank(message = "用户openid不能为空")
    private String openId;

    /**
     * 订单描述
     */
    @NotBlank(message = "订单描述不能为空")
    private String description;

    /***
     * 订单失效时间
     */
    @NotNull(message = "订单失效时间不能为空")
    private Date timeExpire;


    public String getTimeExpireStr() {
        LocalDateTime localDateTime = LocalDateTimeUtils.convertLocalDateTime(this.timeExpire);
        ZonedDateTime zonedDateTime = LocalDateTimeUtils.convertLocalToZonedDateTimeOfZoneId(localDateTime, "Asia/Shanghai");
        OffsetDateTime offsetDateTime = zonedDateTime.toOffsetDateTime();
        return offsetDateTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
    }

    public String getDescription() {
        return description.substring(0, Math.min(description.length(), 60));
    }
    /**
     * 这里是设置是否需要分账，默认为true，表示需要分账
     */
    private Boolean profitSharing = false;
}
