package com.yc.ship.module.trade.controller.admin.order.vo.order;

import com.yc.ship.framework.common.validation.IntEnum;
import com.yc.ship.framework.common.validation.Mobile;
import com.yc.ship.module.trade.dal.dataobject.order.TradeOrderBindDO;
import com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO;
import com.yc.ship.module.trade.dal.dataobject.order.TradeOrderTotalDO;
import com.yc.ship.module.trade.enums.CredentialTypeEnum;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * @author qsl
 */
@Schema(description = "旅行社交易订单创建 Request VO")
@Data
public class ShipTradeOrderCreateReqVO implements Serializable {

    @Schema(description = "分销商ID", example = "MT1231312")
    private Long distributorId;

    @Schema(description = "订单ID")
    private Long orderId;

    @Schema(description = "修改时间")
    private Date updateTime;

    @Schema(description = "是否搬单")
    private boolean moveOrder;

    @Schema(description = "第三方订单号，分销商下单", example = "MT1231312")
    @Hidden
    private String externalOrderNo;

    @Schema(description = "订单号", example = "MT1231312")
    @Hidden
    private String orderNo;

    @Schema(description = "产品名称")
    private String productName;

    @Schema(description = "出行日期", example = "2025-06-01")
    private Date travelDate;

    @Schema(description = "订单项列表", example = "")
    @NotEmpty(message = "订单项列表不能为空")
    @Valid
    private List<OrderItem> itemlList;

    @Schema(description = "订单金额（元）", example = "100")
    @NotNull(message = "订单金额不能为空")
    private BigDecimal amount;

    @Schema(description = "是否审阅", example = "100")
    private Integer isRead;

    @Schema(description = "订单序号", example = "100")
    private Integer orderSort;

    @Schema(description = "订单联系人")
    private String linkMan;

    @Schema(description = "联系人手机")
    private String linkMobile;

    @Schema(description = "联系人邮箱")
    private String linkEmail;

    @Schema(description = "订单附加产品金额（元）", example = "100")
    @NotNull(message = "订单附加产品金额不能为空")
    private BigDecimal spuAmount;

    @Schema(description = "支付金额（元）", example = "90")
    @NotNull(message = "支付金额不能为空")
    private BigDecimal payAmount;

    @Schema(description = "订单总额")
    private BigDecimal realMoney;

    @Schema(description = "定金")
    private BigDecimal deposi;

    @Schema(description = "实付已经金额")
    private BigDecimal realPayAmount;

    @Schema(description = "政策优惠金额")
    private BigDecimal freeAmount;

    @Schema(description = "是否需要补缴费 1是 0 否")
    private Integer isSupplementary;

    @Schema(description = "受损金额")
    private BigDecimal damaged;

    @Schema(description = "补缴费金额")
    private BigDecimal supplementAmount;

    @Schema(description = "取消状态 0：初始  1：待支付（审核通过）2：已支付")
    private Integer damagedStatus;

    @Schema(description = "取消提交时间")
    private LocalDateTime damagedTime;

    @Schema(description = "定金状态")
    private Integer deposiStatus;

    @Schema(description = "定金支付时间")
    private BigDecimal deposiPayTime;

    @Schema(description = "实际总额")
    private BigDecimal realOrderMoney;

    @Schema(description = "订单总额")
    private BigDecimal otherMoney;

    @Schema(description = "折扣ID")
    private Long discountId;

    @Schema(description = "订单联系信息", example = "")
    @NotNull(message = "联系人信息不能为空")
    private OrderUser orderUser;

    @Schema(description = "订单属性", example = "")
    private OrderProperty orderProperty;

    @Schema(description = "订单备注", example = "xx游客岁数较大")
    @Length(max = 120, message = "备注不能超过120个字符")
    private String remark;

    @Schema(description = "其它费用", example = "1")
    private BigDecimal otherAmount;

    @Schema(description = "其它费用备注", example = "xx游客岁数较大")
    private String otherRemark;

    @Schema(description = "携程需要参数，其他情况忽略", example = "")
    private String itemId;

    @Schema(description = "是否完全支付 0 否 1是", example = "")
    private Integer isFullPay;

    @Schema(description = "是否改签 0 否 1是", example = "")
    private Integer isChange;

    @Schema(description = "是否需要审核")
    private Integer confirmType;

    @Schema(description = "是否预订单 0 否 1是", example = "")
    private Integer isYd;

    @Schema(description = "是否补票 0 否 1是", example = "")
    private Integer isTimePay;

    @Schema(description = "是否申请营销政策（0否 1是）", example = "")
    private Integer isMarketing;

    @Schema(description = "是否申请使用营销政策（0否 1是）", example = "")
    private Integer isMarketingUse;

    @Schema(description = "预定团号", example = "")
    private String groupNo;

    @Schema(description = "币种", example = "CNY 字典trade_order_currency")
    private String currency;
    /**
     * 航次ID
     */
    @Schema(description = "航次ID")
    private Long voyageId;

    /**
     * 游轮ID
     */
    @Schema(description = "游轮ID")
    private Long shipId;

    @Schema(description = "是否需要接站服务 0 否 1是")
    private Integer isJz;

    @Schema(description = "接站地址")
    private String jzAddress;

    @Schema(description = "接站联系人")
    private String jzLinkName;

    @Schema(description = "接站联系电话")
    private String jzLinkPhone;


    @Schema(description = "国籍数据")
    private List<TradeOrderCountryReqVO> countryData;

    @Schema(description = "订单汇总信息")
    private TradeOrderTotalVO summary;

    @Schema(description = "订单审核信息")
    private TradeOrderBindDO tradeOrderBindDO;

    @Schema(description = "修改内容")
    private String changedFields1;

    @Schema(description = "房型信息")
    private List<TradeOrderRoomModelVO> roomModelList;


    @Schema(description = "订单项")
    @Data
    @Valid
    public static class OrderItem {
        @Schema(description = "游船产品:楼层ID OR 附加产品:附加产品ID", example = "")
        @NotBlank(message = "楼层ID/附加产品ID不能为空")
        private String productId;

        @Schema(description = "使用日期", example = "0")
        private Date useDate;

        @Schema(description = "产品类型 0 游船产品 1 附加产品", example = "")
        @NotNull(message = "产品类型不能为空")
        private Integer productType;

        @Schema(description = "国籍")
        private String nationality;

        @Schema(description = "成人数量", example = "10")
        @NotNull(message = "成人数量不能为空")
        private Integer crnum1;

        @Schema(description = "儿童数量", example = "10")
        @NotNull(message = "儿童数量不能为空")
        private Integer etnum2;

        @Schema(description = "婴儿数量", example = "10")
        @NotNull(message = "婴儿数量不能为空")
        private Integer yenum3;

        @Schema(description = "陪同数量", example = "10")
        @NotNull(message = "陪同数量不能为空")
        private Integer ptnum;

        @Schema(description = "陪同费用", example = "10")
        private BigDecimal ptamount;


        @Schema(description = "订单明细列表", example = "")
        @NotEmpty(message = "订单明细列表不能为空")
        @Valid
        private List<OrderDetail> detailList;

    }

    @Schema(description = "订单明细")
    @Data
    @Valid
    public static class OrderDetail {

        @Schema(description = "游船产品:楼层ID OR 附加产品:附加产品ID", example = "")
        @NotBlank(message = "楼层ID/附加产品ID不能为空")
        private String productId;

        @Schema(description = "游客ID", example = "")
        private Long visitorId;

        @Schema(description = "产品类型 0 游船产品 1 附加产品 2：赠票", example = "")
        @NotNull(message = "产品类型不能为空")
        private Integer productType;

        @Schema(description = "登船时间")
        private Date boardingTime;

        @Schema(description = "离开时间")
        private Date leaveTime;

        @Schema(description = "单价", example = "")
        private BigDecimal price;

        @Schema(description = "原始单价", example = "")
        private BigDecimal originPrice;

        @Schema(description = "规格类型", example = "full")
        private String specType;

        @Schema(description = "购买数量", example = "10")
        @NotNull(message = "购买数量不能为空")
        private Integer count;

        @Schema(description = "游客列表", example = "")
        @Valid
        private List<Visitor> visitorList;

        @Schema(description = "明细基础", example = "")
        @NotEmpty(message = "明细基础不能为空")
        @Valid
        private List<OrderDetailBase> detailBaseList;
    }

    @Schema(description = "订单明细基础")
    @Data
    @Valid
    public static class OrderDetailBase {


        @Schema(description = "基础产品ID", example = "")
        @NotNull(message = "基础产品ID不能为空")
        private Long productBaseId;

        @Schema(description = "项目ID", example = "")
        @NotNull(message = "项目ID不能为空")
        private Long projectId;

        @Schema(description = "规格ID", example = "")
        @NotNull(message = "规格ID不能为空")
        private Long specificationId;

        @Schema(description = "规格类型", example = "full")
        @NotBlank(message = "规格类型不能为空")
        private String specType;

        @Schema(description = "平台分销的产品编码，平台分销产品必传", example = "123")
        private String platSupplierProductId;

        @Schema(description = "使用日期，定制游时可设置", example = "2024-06-01")
        private Date useDate;

        @Schema(description = "产品资源ID，定制游时可设置", example = "2024-06-01")
        private Long productResourceId;

        @Schema(description = "成本价，定制游时可设置", example = "2024-06-01")
        private BigDecimal costPrice;
    }

    @Schema(description = "游客信息")
    @Data
    @Valid
    public static class Visitor {

        @Schema(description = "游客ID，用于标记是一个人", example = "")
        private String vid;

        @Schema(description = "姓名", example = "")
        private String name;

        @Schema(description = "国籍")
        private String nationality;

        @Schema(description = "年龄")
        private Integer age;

        @Schema(description = "性别 0：未知 1：男 2：女", example = "")
        private Integer gender;
        @Schema(description = "生日")
        private String birthday;

        @Schema(description = "是否重庆中转 0：否 1是")
        private Integer cqzz;

        @Schema(description = "是否宜昌中转 0：否 1是")
        private Integer yczz;

        @Schema(description = "证件号", example = "")
        private String credentialNo;

        @Schema(description = "证件类型", example = "")
        @IntEnum(value = CredentialTypeEnum.class, message = "证件类型不正确")
        private Integer credentialType;

        @Mobile
        @Schema(description = "手机号", example = "")
        private String mobile;

        @Schema(description = "内部平台下单必传，用于区分一票多人券码对应关系", example = "")
        private String otaDetailId;

        @Schema(description = "是否投保 0否 1是", example = "")
        private Integer isInsure;

        @Schema(description = "房间id", example = "")
        private String roomId;

        @Schema(description = "预分房间ID", example = "")
        private String initRoomId;

        @Schema(description = "实际入住房间ID", example = "")
        private String finalRoomId;

        @Schema(description = "同住关系", example = "")
        private String cohabitation;

        @Schema(description = "备注")
        private String remark;
        @Schema(description = "游客类型", example = "")
        private String type;

        @Schema(description = "房间索引ID", example = "")
        private String roomIndexId;

        @Schema(description = "房型ID", example = "")
        private Long roomModelId;
        @Schema(description = "楼层", example = "")
        private Integer floor;
    }


    @Schema(description = "订单联系人")
    @Data
    @Valid
    public static class OrderUser {

        @Schema(description = "姓名", example = "")
        private String contactName;

        @Schema(description = "证件号", example = "")
        private String credentialNo;

        @Schema(description = "证件类型", example = "")
        @IntEnum(value = CredentialTypeEnum.class, message = "证件类型不正确")
        private Integer credentialType;

        @Mobile
        @Schema(description = "手机号", example = "")
        private String mobile;

        @Mobile
        @Schema(description = "邮箱", example = "")
        private String email;

        @Schema(description = "区/县", example = "")
        private String county;

        @Schema(description = "省", example = "")
        private String province;

        @Schema(description = "城市", example = "")
        private String city;

        @Schema(description = "客户", example = "")
        private String clientUser;

    }

    @Schema(description = "订单属性")
    @Data
    @Valid
    public static class OrderProperty {

        @Schema(description = "游客类型", example = "")
        private Integer visitorType;
        @Schema(description = "团队类型", example = "")
        private Integer teamType;
        @Schema(description = "销售渠道", example = "0")
        private Integer sellMethod;
        @Schema(description = "来源ID", example = "123")
        private String sourceId;
        @Schema(description = "来源名称", example = "美团")
        private String sourceName;
        @Schema(description = "会员ID", example = "123")
        private String memberId;
        @Schema(description = "销售员ID", example = "123")
        private String sellerId;
        @Schema(description = "门店ID", example = "123")
        private Long storeId;
        @Schema(description = "门店名称", example = "123")
        private String storeName;
        @Schema(description = "业绩共享人", example = "123")
        private String shareName;
        @Schema(description = "个人分销ID", example = "123")
        private Long personalDistributorId;
        @Schema(description = "优惠券码ID", example = "123")
        private Long couponCodeId;
        @Schema(description = "链接ID", example = "123")
        private Long linkId;
    }


    private TradeOrderDO oldtradeOrderDO;
    private TradeOrderTotalDO oldtradeOrderTotalDO;

}
