package com.backendsys.entity.B2c;

import com.backendsys.entity.validator.RangeArray;
import com.backendsys.entity.validator.RangeStringArray;
import jakarta.validation.constraints.*;
import lombok.Data;

import java.awt.geom.Point2D;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Data
public class B2cOrderDTO {
    public static interface Detail{}
    public static interface Confirm{}
    public static interface Create{}
    public static interface Update{}

    /**
     * b2c_order
     */

    // 从确认订单传递的加密字段
    @NotNull(message = "订单加密信息不能为空", groups = { B2cOrderDTO.Create.class })
    private String encrypted;

    private Long id;
    @NotNull(message = "订单ID不能为空", groups = { B2cOrderDTO.Detail.class, B2cOrderDTO.Update.class })
    private Long order_id;


    @NotEmpty(message = "规格不能为空", groups = { B2cOrderDTO.Confirm.class })
    private List<Map<String, Object>> sku;

    @Size(max = 32, message = "订单编码长度不超过 {value}", groups = { B2cOrderDTO.Update.class })
    private String order_code;

    // (cart 从购物车, sku 从规格)
    // @NotNull(message = "订单来源不能为空", groups = { B2cOrderDTO.Create.class })
    @RangeArray(message="订单来源取值有误，范围应是(1从购物车, 2从规格ID)", value = {"1", "2"}, groups = { B2cOrderDTO.Create.class })
    private Integer order_source;

    // 当 { order_source: 'sku' } 时，{ spec_sku_id } 必填
    @NotNull(message = "规格ID不能为空", groups = { B2cOrderDTO.Update.class })
    private Long spec_sku_id;

    private Long member_id;

    private String member_open_id;
    //
    //@Size(max = 200, message = "配送地址长度不超过 {max} 字符", groups = { B2cOrderDTO.Create.class, B2cOrderDTO.Update.class })
    private String recipient_address;
    private Point2D.Double recipient_point;
    //@Digits(integer = 9, fraction = 2, message = "配送金额最多支持 {integer} 位数字且小数点后最多 {fraction} 位", groups = { B2cOrderDTO.Create.class, B2cOrderDTO.Update.class })
    private BigDecimal recipient_price;

    /*
        public class YourEntity {
            @Valid
            @NotNull(message = "收件人坐标不能为空")
            private Point2D.Double recipient_point;
            // Getter and Setter
            // Other fields and methods
        }
        // 自定义校验器
        public class LatitudeValidator implements ConstraintValidator<ValidLatitude, Point2D.Double> {
            @Override
            public boolean isValid(Point2D.Double value, ConstraintValidatorContext context) {
                if (value == null) {
                    return true; // 允许为空
                }
                double latitude = value.getY();
                // 进行纬度范围检查
                return latitude >= -90.0 && latitude <= 90.0;
            }
        }
        // 自定义注解
        @Target({ ElementType.FIELD })
        @Retention(RetentionPolicy.RUNTIME)
        @Constraint(validatedBy = LatitudeValidator.class)
        public @interface ValidLatitude {
            String message() default "纬度值超出有效范围";
            Class<?>[] groups() default {};
            Class<? extends Payload>[] payload() default {};
        }
     */

    // @NotNull(message = "总价不能为空", groups = { B2cOrderDTO.Create.class, B2cOrderDTO.Update.class })
    // @Digits(integer = 9, fraction = 2, message = "总价最多支持 {integer} 位数字且小数点后最多 {fraction} 位", groups = { B2cOrderDTO.Create.class, B2cOrderDTO.Update.class })
    private BigDecimal final_total_price;

    @NotNull(message = "支付方式不能为空", groups = { B2cOrderDTO.Create.class, B2cOrderDTO.Update.class })
    @RangeStringArray(message="支付方式取值有误，范围应是(WeChatPay微信, AliPay支付宝)", value = {"WeChatPay", "AliPay"}, groups = { B2cOrderDTO.Create.class, B2cOrderDTO.Update.class })
    private String pay_method;

    private Date pay_time;

    @RangeArray(message="支付状态取值有误，范围应是(-2已超时, -1待支付, 1已支付, 2已退款)", value = {"-2", "-1", "1", "2"}, groups = { B2cOrderDTO.Update.class })
    private Integer pay_status;

    private String prepay_id;
    private Date pay_refund_time;

    @RangeArray(message="退款状态取值有误，范围应是(-1退款失败, 1退款中, 2退款成功)", value = {"-1", "1", "2"}, groups = { B2cOrderDTO.Update.class })
    private Integer pay_refund_status;

    @RangeArray(message="取消订单方式取值有误，范围应是(1会员, 2商家)", value = {"1", "2"}, groups = { B2cOrderDTO.Update.class })
    private Integer cancel_order_way;

    @Size(max = 200, message = "取消订单原因长度不超过 {max} 字符", groups = { B2cOrderDTO.Update.class })
    private String cancel_order_reason;

    @RangeArray(message="订单状态取值有误，范围应是(-2取消订单, -1预下单, 1已下单, 2已收货, 3待评价, 4已完成)", value = {"-2", "-1", "1", "2", "3", "4"}, groups = { B2cOrderDTO.Update.class })
    private Integer status;

    @RangeArray(message="是否已阅取值有误，范围应是(-1未阅, 1已阅)", value = {"-1", "1"}, groups = { B2cOrderDTO.Update.class })
    private Integer is_readed;

    @Size(max = 200, message = "取消订单原因长度不超过 {max} 字符", groups = { B2cOrderDTO.Update.class })
    private String notes;

    private String create_time_begin;
    private String create_time_end;

    private String create_time;
    private String update_time;

}
