package com.tzy.pojo.app;

import lombok.Data;
import org.teasoft.bee.osql.annotation.Ignore;

import javax.persistence.Column;
import javax.persistence.Table;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;

/**
 * @Description  
 * @Author  Hunter
 * @Date 2022-02-16 
 */

@Table ( name ="app_user_point_record" )
@Data
public class AppUserPointRecord  implements Serializable {

	private static final long serialVersionUID =  1457745123374227770L;

	/**
	 * id
	 */
   	@Column(name = "id" )
	private Long id;

	/**
	 * 用户id
	 */
   	@Column(name = "user_id" )
	private Long userId;

	private String type;

	/**
	 * 当前积分
	 */
   	@Column(name = "curr_point" )
	private Long currPoint;

	/**
	 * 上次积分
	 */
   	@Column(name = "last_point" )
	private Long lastPoint;

	/**
	 * 增加积分
	 */
   	@Column(name = "change_point" )
	private Long changePoint;

	/**
	 * 订单id
	 */
   	@Column(name = "order_id" )
	private Long orderId;
	private Long merchantId;

	private String orderNo;

	/**
	 * 创建时间
	 */
   	@Column(name = "create_time" )
	private Date createTime;
	/** 倍率.默认1 */
	private Double pointRate;
	@Ignore
	/**展示积分*/
	private BigDecimal showPoint;
	@Ignore
	private String pointTypeMsg;
	private String refId;
	@Ignore
	private String refundStatus;
//	@Ignore
//	private Integer refundLimitDay;

	public BigDecimal getShowPoint() {
		Integer showPointRate = getShowPointRateByType(this.type);
		return new BigDecimal(changePoint.toString()).divide(new BigDecimal(showPointRate.toString()),2, RoundingMode.HALF_DOWN);
	}

	private Integer getShowPointRateByType(String type){
//		if (type.startsWith("mer_act") || type.startsWith("hb_act")) {
//			return 1;
//		}
		int rate=100;
		switch (type){
			case "lucky_point_2023_618":
				rate = 500;
				break;
			case "user_growth":
				rate = 1000;
				break;
			default:
				// 品牌会员成长值
				if(type.startsWith("diy_brand_growth_")){
					rate = 1000;
					break;
				}
				break;
		}
		return rate;
	}
}
