package com.slodon.b2b2c.vo.promotion;

import com.slodon.b2b2c.core.constant.CouponConst;
import com.slodon.b2b2c.core.util.TimeUtil;
import com.slodon.b2b2c.promotion.pojo.Coupon;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

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

import static com.slodon.b2b2c.vo.promotion.CouponListVO.dealUseTypeValue;
import static com.slodon.b2b2c.vo.promotion.CouponVO.dealCouponTypeValue;

/**
 * 封装店铺发放的优惠券VO对象
 *
 * @author wuxy
 */
@Data
public class StoreCouponVO implements Serializable {

    private static final long serialVersionUID = -6347971421685725921L;
    @ApiModelProperty("优惠券id")
    private Integer couponId;

    @ApiModelProperty("优惠券名称")
    private String couponName;

    @ApiModelProperty("优惠内容")
    private String couponContent;

    @ApiModelProperty("优惠券使用说明")
    private String description;

    @ApiModelProperty("优惠券类型(1-固定金额券；2-折扣券（折扣比例）；3-随机金额券）")
    private Integer couponType;

    @ApiModelProperty("优惠券类型值(1-固定金额券；2-折扣券（折扣比例）；3-随机金额券）")
    private String couponTypeValue;

    @ApiModelProperty("统计信息-已经领取数量")
    private Integer receivedNum;

    @ApiModelProperty("统计信息-已使用数量")
    private Integer usedNum;

    @ApiModelProperty("优惠金额;折扣")
    private String publishValue;

    @ApiModelProperty("发行限制-随机金额的最大值")
    private BigDecimal randomMax;

    @ApiModelProperty("发行限制-随机金额最小值")
    private BigDecimal randomMin;

    @ApiModelProperty("发行限制-发行数量")
    private Integer publishNum;

    @ApiModelProperty("发行限制-领取开始时间")
    private String publishStartTime;

    @ApiModelProperty("发行限制-领取结束时间")
    private String publishEndTime;

    @ApiModelProperty("使用开始时间")
    private String effectiveStart;

    @ApiModelProperty("使用结束时间")
    private String effectiveEnd;

    @ApiModelProperty("发行限制-限制领取次数，0-为不限制，1-限制领1次，默认为1")
    private Integer limitReceive;

    @ApiModelProperty("店铺id")
    private Long storeId;

    @ApiModelProperty("店铺名称")
    private String storeName;

    @ApiModelProperty("订单金额使用限制，超过quota后可用")
    private BigDecimal limitQuota;

    @ApiModelProperty("是否推荐 1、推荐；0、不推荐")
    private Integer isRecommend;

    @ApiModelProperty("用户是否领取:0-未领取，1-已领取,2-已抢完")
    private Integer isReceive;

    @ApiModelProperty("适用商品类型：1-全部商品，2-指定商品")
    private Integer useType;

    @ApiModelProperty("适用商品类型值：1-全部商品，2-指定商品")
    private String useTypeValue;

    @ApiModelProperty("优惠券使用商品类型为指定商品时返商品id串")
    private String goodsIds;

    @ApiModelProperty("已领取百分比")
    private Integer receivePercent;

    public StoreCouponVO(Coupon coupon) {
        couponId = coupon.getCouponId();
        couponName = coupon.getCouponName();
        couponContent = coupon.getCouponContent();
        description = coupon.getDescription();
        couponType = coupon.getCouponType();
        couponTypeValue = dealCouponTypeValue(coupon.getCouponType());
        receivedNum = coupon.getReceivedNum();
        usedNum = coupon.getUsedNum();
        randomMax = coupon.getRandomMax();
        randomMin = coupon.getRandomMin();
        publishNum = coupon.getPublishNum();
        publishStartTime = TimeUtil.dealTime(coupon.getPublishStartTime());
        publishEndTime = TimeUtil.dealTime(coupon.getPublishEndTime());
        if (coupon.getEffectiveTimeType() == CouponConst.EFFECTIVE_TIME_TYPE_2) {
            effectiveStart = TimeUtil.dealTime(new Date());
            effectiveEnd = TimeUtil.dealTime(TimeUtil.getDateApartDay(coupon.getCycle()));
        } else {
            effectiveStart = TimeUtil.dealTime(coupon.getEffectiveStart());
            effectiveEnd = TimeUtil.dealTime(coupon.getEffectiveEnd());
        }
        limitReceive = coupon.getLimitReceive();
        storeId = coupon.getStoreId();
        storeName = coupon.getStoreName();
        limitQuota = coupon.getLimitQuota();
        isRecommend = coupon.getIsRecommend();
        useType = coupon.getUseType();
        useTypeValue = dealUseTypeValue(coupon.getUseType());
        int receivedNum = (coupon.getReceivedNum() * 100) / coupon.getPublishNum();
        receivePercent = receivedNum == 0 && coupon.getReceivedNum() > 0 ? 1 : receivedNum;
    }
}
