package com.gxwebsoft.shop.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.*;
import java.math.BigDecimal;
import java.util.List;

/**
 * 订单创建请求DTO
 *
 * @author 科技小王子
 * @since 2025-01-26
 */
@Data
@Schema(name = "OrderCreateRequest", description = "订单创建请求")
public class OrderCreateRequest {

    @Schema(description = "订单编号")
    private String orderNo;

    @Schema(description = "订单类型，0商城订单 1预定订单/外卖 2会员卡")
    @NotNull(message = "订单类型不能为空")
    @Min(value = 0, message = "订单类型值无效")
    @Max(value = 2, message = "订单类型值无效")
    private Integer type;

    @Schema(description = "订单类型 1-及时自配送 2-自提 3-预约自配送 4-发快递 5-配送【系统自动识别电子围栏内转及时配送，电子围栏外发快递】")
    private Integer orderType;

    @Size(max = 60, message = "备注长度不能超过60个字符")
    @Schema(description = "订单标题")
    private String title;

    @Schema(description = "快递/自提")
    private Integer deliveryType;

    @Schema(description = "下单渠道，0小程序预定 1俱乐部训练场 3活动订场")
    private Integer channel;

    @Schema(description = "商户ID")
    private Long merchantId;

    @Schema(description = "商户名称")
    private String merchantName;

    @Schema(description = "商户编号")
    private String merchantCode;

    @Schema(description = "店铺ID")
    private Integer storeId;

    @Schema(description = "使用的优惠券id")
    private Integer couponId;

    @Schema(description = "使用的会员卡id")
    private String cardId;

    @Schema(description = "关联收货地址")
    private Integer addressId;

    @Schema(description = "收货地址")
    private String address;

    @Schema(description = "收货人姓名")
    private String realName;

    @Schema(description = "地址纬度")
    private String addressLat;

    @Schema(description = "地址经度")
    private String addressLng;

    @Schema(description = "自提店铺id")
    private Integer selfTakeMerchantId;

    @Schema(description = "自提店铺")
    private String selfTakeMerchantName;

    @Schema(description = "配送开始时间")
    private String sendStartTime;

    @Schema(description = "配送结束时间")
    private String sendEndTime;

    @Schema(description = "发货店铺id")
    private Integer expressMerchantId;

    @Schema(description = "发货店铺")
    private String expressMerchantName;

    @Schema(description = "订单总额")
    @NotNull(message = "订单总额不能为空")
    @DecimalMin(value = "0.01", message = "订单总额必须大于0")
    @Digits(integer = 10, fraction = 2, message = "订单总额格式不正确")
    private BigDecimal totalPrice;

    @Schema(description = "减少的金额，使用VIP会员折扣、优惠券抵扣、优惠券折扣后减去的价格")
    @DecimalMin(value = "0", message = "减少金额不能为负数")
    private BigDecimal reducePrice;

    @Schema(description = "实际付款")
    @DecimalMin(value = "0", message = "实际付款不能为负数")
    private BigDecimal payPrice;

    @Schema(description = "用于统计")
    private BigDecimal price;

    @Schema(description = "价钱，用于积分赠送")
    private BigDecimal money;

    @Schema(description = "教练价格")
    private BigDecimal coachPrice;

    @Schema(description = "购买数量")
    @Min(value = 1, message = "购买数量必须大于0")
    private Integer totalNum;

    @Schema(description = "教练id")
    private Integer coachId;

    @Schema(description = "来源ID，存商品ID")
    private Integer formId;

    @Schema(description = "支付类型，0余额支付, 1微信支付，102微信Native，2会员卡支付，3支付宝，4现金，5POS机，6VIP月卡，7VIP年卡，8VIP次卡，9IC月卡，10IC年卡，11IC次卡，12免费，13VIP充值卡，14IC充值卡，15积分支付，16VIP季卡，17IC季卡，18代付")
    private Integer payType;

    @Schema(description = "代付支付方式")
    private Integer friendPayType;

    @Schema(description = "优惠类型：0无、1抵扣优惠券、2折扣优惠券、3、VIP月卡、4VIP年卡，5VIP次卡、6VIP会员卡、7IC月卡、8IC年卡、9IC次卡、10IC会员卡、11免费订单、12VIP充值卡、13IC充值卡、14VIP季卡、15IC季卡")
    private Integer couponType;

    @Schema(description = "优惠说明")
    private String couponDesc;

    @Schema(description = "预约详情开始时间数组")
    private String startTime;

    @Schema(description = "备注")
    @Size(max = 500, message = "备注长度不能超过500字符")
    private String comments;

    @Schema(description = "排序号")
    private Integer sortNumber;

    @Schema(description = "租户id")
    @NotNull(message = "租户ID不能为空")
    private Integer tenantId;

    @Schema(description = "秒杀活动ID")
    private Integer activityId;

    @Schema(description = "订单商品列表")
    @Valid
    @NotEmpty(message = "订单商品列表不能为空")
    private List<OrderGoodsItem> goodsItems;

    /**
     * 订单商品项
     */
    @Data
    @Schema(name = "OrderGoodsItem", description = "订单商品项")
    public static class OrderGoodsItem {
        @Schema(description = "秒杀活动ID")
        private Integer activityId;

        @Schema(description = "商品ID", required = true)
        @NotNull(message = "商品ID不能为空")
        private Integer goodsId;

        @Schema(description = "商品SKU ID")
        private Integer skuId;

        @Schema(description = "商品数量", required = true)
        @NotNull(message = "商品数量不能为空")
        @Min(value = 1, message = "商品数量必须大于0")
        private Integer quantity;

        @Schema(description = "支付类型")
        private Integer payType;

        @Schema(description = "规格信息，如：颜色:红色|尺寸:L")
        private String specInfo;
    }
}
