package com.sonic.lion.domain.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sonic.lion.domain.enums.ProductType;
import com.sonic.lion.enums.MemberType;
import lombok.*;

import java.math.BigDecimal;
import java.util.Date;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "t_app_product", autoResultMap = true)
public class AppStoreProduct {

    @TableId(type = IdType.AUTO)
    private Long id;

    private String platform;

    /**
     * 产品类型  连续购买订阅 和 非连续
     */
    private ProductType productType;

    /**
     * 订阅套餐类型
     */
    private MemberType memberType;

    private PERIOD period;

    /**
     * 应用id
     */
    private String bundleId;

    /**
     * 内购商品项id
     */
    private String productId;

    /**
     * 优惠多少 百分比
     */
    private String discount;

    /**
     * 得到的Buff
     */
    private Long chargeAmount;

    /**
     * 支付金额
     */
    private Long payAmount;

    private Date createTime;

    private Date editTime;

    @TableField("is_delete")
    private Boolean deleted;

    private String version;

    @Getter
    public  enum PERIOD{
        SUB_MONTH(30*86400 ,1 ),SUB_SEASON(90*86400, 3),SUB_YEAR(360*86400,  12);
        int seconds;
        int month;
        PERIOD(int value,int month){
            this.seconds = value;
            this.month = month;
        }
    }

    /**
     * 折合每月多少
     */
    public Long getMonthlyPrice(){
        if(PERIOD.SUB_MONTH.equals(period)){
            return payAmount;
        }
        if(PERIOD.SUB_SEASON.equals(period)){
           return new BigDecimal(payAmount) .divide(new BigDecimal("3"), 0, BigDecimal.ROUND_HALF_UP).longValue();
        }
        if(PERIOD.SUB_YEAR.equals(period)){
            return new BigDecimal(payAmount) .divide(new BigDecimal("12"), 0, BigDecimal.ROUND_HALF_UP).longValue();
        }
        return 0L;
    }
}