package com.yonge.cooleshow.biz.dal.wrapper;

import com.baomidou.mybatisplus.annotation.TableField;
import com.yonge.cooleshow.biz.dal.enums.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.Optional;

public class VipCardRecordWrapper {

    @Data
    public static class UserVip{


        @ApiModelProperty(value = "vip类型 VIP:会员 SVIP:SVIP，PERMANENT_SVIP:永久SVIP，NOT_VIP:不是vip")
        private EVipType vipType;


        @ApiModelProperty(value = "vip过期类型 VIP:会员 SVIP:SVIP，ALL_VIP:全vip")
        private EVipType expireVipType;


        @ApiModelProperty(value = "vip结束时间")
        private Date vipEndDate;


        @ApiModelProperty(value = "vip剩余天数")
        private Integer vipEndDays =0;

        @ApiModelProperty(value = "svip结束时间")
        private Date svipEndDate;


        @ApiModelProperty(value = "svip剩余天数")
        private Integer svipEndDays =0;

        @ApiModelProperty("vip失效天数")
        private Integer vipExpireDays;

        @ApiModelProperty("Svip失效天数")
        private Integer svipExpireDays;
    }

    @ApiModel("添加/扣减会员")
    @Data
    public static class AddVipCardRecord {

        @ApiModelProperty("用户ID")
        @NotNull(message = "用户不能为空")
        private Long userId;

        @ApiModelProperty("用户类型")
        @NotNull(message = "用户类型不能为空")
        private ClientEnum clientType;

        @ApiModelProperty("状态 ADD:新增，DEDUCTION:扣减,UPDATE:变更")
        @NotNull
        private EVipRecordStatus status;

        @ApiModelProperty("会员类型，VIP,SVIP")
        @NotNull
        private EVipType vipType;

        @ApiModelProperty("时间类型 DAY:天 MONTH:月 ，QUARTERLY : 季度 YEAR_HALF ： 半年 YEAR:年,永久：PERMANENT")
        @NotNull
        private PeriodEnum type;

        @ApiModelProperty("数量")
        @Min(value = 1, message = "最小数量为1")
        @Max(value = 999, message = "最大数量为999")
        private Integer times;

        @ApiModelProperty("扣减原因")
        @NotNull
        private String reason;

        @ApiModelProperty("是否发送推送,是：true,否：false")
        @NotNull
        private Boolean sendMsg;

        @ApiModelProperty(value = "创建人",hidden = true)
        private Long createBy;

        @ApiModelProperty(value = "转换VIP天数",hidden = true)
        private Integer vipDays;


        @ApiModelProperty("来源类型 ： ACTIVITY ：活动 ，ORDER:订单")
        private SourceTypeEnum sourceType;

        private String orderNo;
        private Long vipCardId;
        private String subOrderNo;

        private boolean orderFlag = false;
    }

    @Data
    public static class UserVipInfo {

        @ApiModelProperty("用户ID")
        private Long userId;

        @ApiModelProperty("当前会员类型")
        private EUserVipType currentVipType;

        @ApiModelProperty("VIP的结束时间")
        private Date currentVipSvipEndTime;

        @ApiModelProperty("vip结束时间")
        private Date vipEndTime;

        @ApiModelProperty("svip结束时间")
        private Date svipEndTime;

        @ApiModelProperty("svip结束时间")
        private Date perSvipEndTime;

        public Date getCurrentVipSvipEndTime() {
            if (EUserVipType.NORMAL.equals(currentVipType)) {
                return Optional.ofNullable(vipEndTime).orElse(svipEndTime);
            } else if (EUserVipType.VIP.equals(currentVipType)) {
                return vipEndTime;
            } else {
                if (perSvipEndTime != null) { // 永久SVIP
                    return null;
                } else {
                    return svipEndTime;
                }
            }
        }
    }
}
