package com.cyksj.model.views;

import com.cyksj.model.entity.Coupon;
import com.cyksj.model.entity.CouponUser;
import com.ejlchina.searcher.bean.DbField;
import com.ejlchina.searcher.bean.DbIgnore;
import com.ejlchina.searcher.bean.SearchBean;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.Date;

/*
 *项目名: netflix
 *文件名: CouponUserView
 *创建者: JavaZou
 *创建时间:2022/11/18 12:12
 */
@Getter
@Setter
@SearchBean(tables = "coupon_user cu left join coupon_active ca on ca.id = cu.coupon_active_id" +
		" left join coupon c on c.id = cu.coupon_id left join coupon_classification cc on cc.id = c.classification_id")
public class CouponUserView {
	@DbField("cu.id")
	private Long id;

	/**
	 * 获取渠道
	 */
	@DbField("cu.channel")
	private CouponUser.Channel channel;

	/**
	 * 优惠券使用状态
	 */
	@DbField("cu.status")
	private CouponUser.Status couponUserStatus;

	/**
	 * 用户id
	 */
	@DbField("cu.user_id")
	private Long userId;

	/**
	 * 优惠券id
	 */
	@DbField("c.id")
	private Long couponId;

	/**
	 * 优惠券发放id
	 */
	@DbField("ca.id")
	private Long couponActiveId;

	/**
	 * 优惠券名称
	 */
	@DbField("c.name")
	private String name;

	@DbField("cc.id")
	private Long classificationId;

	@DbField("cc.name")
	private String couponClassificationName;

	/**
	 * 优惠券平台类型
	 */
	@DbField("c.goods_type")
	private Coupon.GoodsType goodsType;

	/**
	 * 优惠券类型
	 */
	@DbField("c.type")
	private Coupon.Type type;

	/**
	 * 可用满减卷金额条件
	 */
	@DbField("c.reduce_condition")
	private BigDecimal reduceCondition;

	@DbField("c.scope")
	private Coupon.Scope scope;

	/**
	 * 抵扣金额
	 */
	@DbField("c.reduce_money")
	private BigDecimal reduceMoney;

	/**
	 * 折扣
	 */
	@DbField("c.discount")
	private BigDecimal discount;

	/**
	 * 平台规格集合
	 */
	@DbField("c.goods_sku_ids")
	private String goodsSkuIds;

	@DbIgnore
	private String goodsSkuStr;

	/**
	 * 是否是有效时间
	 */
	@DbField("c.is_valid_time")
	private Boolean isValidTime;

	/**
	 * 起始有效时间
	 */
	@DbField("cu.valid_start_time")
	private Date validStartTime;

	/**
	 * 领取有效天数
	 */
	@DbField("c.valid_days")
	private Integer validDays;

	@DbField("c.valid_hours")
	private Integer validHours;

	/**
	 * 截止有效时间
	 */
	@DbField("cu.valid_end_time")
	private Date validEndTime;

	@DbIgnore
	private Long validEndTimestamp;

	@DbField("c.use_scope")
	private Coupon.UseScope useScope;

	/**
	 * 发放优惠券状态(默认启用)
	 */
	@DbField("ca.status")
	private Boolean status;

	/**
	 * 有效状态(默认有效)
	 */
	@DbField("ca.expiry_status")
	private Boolean expiryStatus;

	@DbField("case when cu.status = 'unused' then 0" +
			" when cu.status = 'expired' then 1" +
			" when cu.status = 'invalid' then 2" +
			" when cu.status = 'used' then 3" +
			" end")
	@JsonIgnore
	private Integer orderBy;

	/**
	 * 0不可用/1可用
	 */
	@DbIgnore
	private Boolean isAvailable;

	/**
	 * 不可用原因
	 */
	@DbIgnore
	private String reason;

	@DbField("cu.created_time")
	private Date createdTime;

	@DbIgnore
	private String goodsImg;
}
