package com.tzy.common.dto.act;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.tzy.common.constant.Constants;
import lombok.Data;
import lombok.experimental.Accessors;

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

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@Accessors(chain = true)
public class GroupAmountActDTO implements Serializable {

    private Long merchantId;
    private String merchantName;
    private String merchantAvatar;

    private Long infoId;
    private String infoName;
    private String code;
    private String liveCode;
    private String sport;
    private Date startTime;
    private Long startTimestamp;
    private String pointType;
    private String pointTypeMsg;
    private Long actId;
    private Long refActId;
    private String refSubType;
    private String subType;
    private String ruleConfig;
    private Date actStartTime;
    private Long actStartTimestamp;
    private Date actEndTime;
    private Long actEndTimestamp;
    private String actImg;
    @JsonIgnore
    private Long fellowId;
    private boolean fellowAble;
    //当日是否参与
    private boolean joinAble;
    //关联活动条件人数
    private int refActCondNum;
    //关联活动参与人数
    private int refActNum;
    private String shareMsg;
    //原价
    private BigDecimal totalUnitPrice;
    //已砍总结
    private BigDecimal totalDecrPrice;
    //当前活动价
    private BigDecimal totalActPrice;
    //当前单价
    private BigDecimal actUnitPrice;
    //分享来源用户id
    private Long shareUserId;
    private String shareUserNickname;
    private String shareUserAvatar;
    private Integer shareUserMember;
    private String popupImg;
    private String rankPrizeImg;
    private Integer realSoldNum;
    private Integer infoNum;
    private Integer infoStatus;

    public boolean isFellowAble() {
        return fellowId!=null;
    }

    public Long getActEndTimestamp() {
        return actEndTime.getTime();
    }

    public Long getActStartTimestamp() {
        return actStartTime.getTime();
    }

    public Long getStartTimestamp() {
        if (startTime != null) {
            return startTime.getTime();
        }
        return System.currentTimeMillis();
    }
    public Date getstartTime() {
        if (startTime != null) {
            return startTime;
        }
        return null;
    }

    public BigDecimal getTotalDecrPrice() {
        if (totalDecrPrice == null) {
            return BigDecimal.ZERO;
        }
        // 拼豆模式
        if(pointType != null && pointType.startsWith(Constants.POINT_TYPE_MERCHANT_ACT_PRE)){
           return totalDecrPrice;
        }
        return totalDecrPrice.divide(Constants.HUNDRED, 2, RoundingMode.HALF_DOWN);
    }
}