package com.gingersoft.gsa.cloud.database.bean;

import com.gingersoft.gsa.cloud.base.utils.MoneyUtil;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Property;

import java.util.Date;
import org.greenrobot.greendao.annotation.Generated;

/**
 * 作者：ELEGANT_BIN
 * 版本：1.6.0
 * 创建日期：2020-04-08
 * 修订历史：2020-04-08
 * 描述：
 */
@Entity
public class Discount {

    /**
     * ID
     */
    @Property(nameInDb = "_id")
    @Id(autoincrement = true)
    private Long id;

    private Integer restaurant_id;
    /**金額*/
    private Double amount;
    /**折扣*/
    private Double discount_value;
    /**类型#0:金额;1:折扣;*/
    private Integer type;
    /**状态#0:启用;1:禁用;*/
    private Integer status;
    /**折扣描述*/
    private String remark;
    private Date begin_time;
    private Date end_time;

    @Generated(hash = 947827493)
    public Discount(Long id, Integer restaurant_id, Double amount,
            Double discount_value, Integer type, Integer status, String remark,
            Date begin_time, Date end_time) {
        this.id = id;
        this.restaurant_id = restaurant_id;
        this.amount = amount;
        this.discount_value = discount_value;
        this.type = type;
        this.status = status;
        this.remark = remark;
        this.begin_time = begin_time;
        this.end_time = end_time;
    }
    @Generated(hash = 1777606421)
    public Discount() {
    }
    public Long getId() {
        return this.id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Integer getRestaurant_id() {
        return this.restaurant_id;
    }
    public void setRestaurant_id(Integer restaurant_id) {
        this.restaurant_id = restaurant_id;
    }
    public Double getAmount() {
        return this.amount;
    }
    public void setAmount(Double amount) {
        this.amount = amount;
    }
    public Double getDiscount_value() {
        return this.discount_value;
    }
    public void setDiscount_value(Double discount_value) {
        this.discount_value = discount_value;
    }
    public Integer getType() {
        return this.type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
    public Integer getStatus() {
        return this.status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
    public String getRemark() {
        return this.remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }
    public Date getBegin_time() {
        return this.begin_time;
    }
    public void setBegin_time(Date begin_time) {
        this.begin_time = begin_time;
    }
    public Date getEnd_time() {
        return this.end_time;
    }
    public void setEnd_time(Date end_time) {
        this.end_time = end_time;
    }


    /**
     * 計算折扣金額
     * @param discount
     * @param sourcePrice
     * @return
     */
    public static double calculationDiscount(Discount discount , double sourcePrice){
        double discountPrice;
        if(discount.getType() == 0){
            //金額折扣
            discountPrice =  discount.getAmount();
        }else {
            //百分比折扣
            discountPrice = sourcePrice * discount.getDiscount_value();
        }
        if(sourcePrice < discountPrice){
            //折扣金額不能超出總額
            discountPrice = sourcePrice;
        }else {
            discountPrice = sourcePrice - discountPrice;
        }
        return -MoneyUtil.get_ItemDecimals_money(discountPrice);
    }

}
