package com.yuchen.saas.park.api.vo.property;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.thinkunion.park.service.common.utils.AmtUtil;
import com.yuchen.saas.park.api.enums.property.BillStatusEnum;
import com.yuchen.saas.park.api.enums.property.CreateBillTypeEnum;
import com.yuchen.saas.park.api.enums.property.PayStatusEnum;
import com.yuchen.saas.park.api.enums.property.PriceUnitTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

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

@Data
@ApiModel(value="账单列表信息")
public class PropertyBillListVo implements Serializable {

    /**
     * 账单id
     */
    private Long id;

    private Long parkId;

    private Long houseId;
    /**客户id*/
    private Long customerId;
    /**收费标准id*/
    private Long feeId;
    /**费用项目id*/
    private Long feeItemId;

    /**
     * 账单状态
     */
    private Integer billStatus;
    /**
     * 账单状态名称
     */
    private String billStatusName;
    public String getBillStatusName() {
        return BillStatusEnum.convert(this.billStatus).getDesc();
    }

    /**
     * 账单状态
     */
    @ApiModelProperty
    private Integer payStatus;
    /**
     * 账单状态名称
     */
    private String payStatusName;
    public String getPayStatusName() {
        return PayStatusEnum.convert(this.payStatus).getDesc();
    }

    @JsonIgnore
    private Long priceFen;
    /**
     * 价格;单位：元
     */
    private BigDecimal price;
    public BigDecimal getPrice() {
        return AmtUtil.fenToYuanObj(this.priceFen);
    }


    @JsonIgnore
    private Integer priceUnitType;

    /**
     * 计价单位
     */
    private String priceUnitTypeName;
    public String getPriceUnitTypeName() {
        if (priceUnitType != null) {
            return PriceUnitTypeEnum.convert(this.priceUnitType).getDesc();
        }
        return "";
    }

    @JsonIgnore
    private long receivableAmtFen;
    /**
     * 应收金额;单位：分元
     */
    private BigDecimal receivableAmt;
    public BigDecimal getReceivableAmt() {
        return AmtUtil.fenToYuan(this.receivableAmtFen);
    }

    /**
     * 计算数量
     */
    private BigDecimal billableQuantity;
    /**
     * 账单开始时间
     */
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    private Date startDate;
    /**
     * 账单结束时间
     */
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    private Date endDate;
    /**
     * 应收日期
     */
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    private Date receivableDate;

    /**
     * 直接减免金额
     */
    @JsonIgnore
    private long directReductionAmtFen;
    /**
     * 直接减免金额;单位：元
     */
    private BigDecimal directReductionAmt;
    public BigDecimal getDirectReductionAmt() {
        return AmtUtil.fenToYuan(this.directReductionAmtFen);
    }
    /**
     * 缴费减免金额
     */
    @JsonIgnore
    private long payReductionAmtFen;
    /**
     * 优惠券减免金额;单位：分
     */
    @JsonIgnore
    private long couponAmtFen;

    /**
     * 缴费优惠;单位：元
     */
    private BigDecimal payReductionAmt;
    public BigDecimal getPayReductionAmt() {
        // 缴费优惠 = 优惠券减免 + 缴费减免活动
        return AmtUtil.fenToYuanObj(payReductionAmtFen + couponAmtFen);
    }


    /**
     * 违约金计算起始日
     */
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    private Date breachDate;
    /**
     * 违约金计算方式;1-单利，2-利滚利
     */
    private Integer breachCalcType;
    /**
     * 违约金每天收取比例
     */
    private BigDecimal breachRate;

    /**
     * 是否减少滞纳金; 1-是，0-否
     */
    private int isReduceBreach;

    @JsonIgnore
    private long reductionBreachAmtFen;
    /**
     * 减免的滞纳金;单位：元
     */
    private BigDecimal reductionBreachAmt;
    public BigDecimal getReductionBreachAmt() {
        return AmtUtil.fenToYuan(reductionBreachAmtFen);
    }

    /**应收滞纳金*/
    @JsonIgnore
    private long breachAmtFen;
    /**
     * 应收滞纳金;单位：元
     */
    private BigDecimal breachAmt;
    public BigDecimal getBreachAmt() {
        return AmtUtil.fenToYuan(this.breachAmtFen);
    }
    /**
     * 是否减少费用调整; 1-是，0-否
     */
    private int isReduceReadjust;

    /**调整金额*/
    @JsonIgnore
    private long readjustAmtFen;
    /**
     * 调整金额;单位：元
     */
    private BigDecimal readjustAmt;
    public BigDecimal getReadjustAmt() {
        return AmtUtil.fenToYuan(readjustAmtFen);
    }

    @JsonIgnore
    private long taxAmtFen;
    /**
     * 税费金额;单位：元
     */
    private BigDecimal taxAmt;
    public BigDecimal getTaxAmt() {
        return AmtUtil.fenToYuan(this.taxAmtFen);
    }

    @JsonIgnore
    private long payAmtFen;
    /**
     * 已缴金额;单位：元
     */
    private BigDecimal payAmt;
    public BigDecimal getPayAmt() {
        return AmtUtil.fenToYuan(this.payAmtFen);
    }

    @JsonIgnore
    private long noPayAmtFen;
    /**
     * 未缴金额;单位：元
     */
    private BigDecimal noPayAmt;
    public BigDecimal getNoPayAmt() {
        return AmtUtil.fenToYuan(this.noPayAmtFen);
    }

    /**
     * 合计应收金额; 分
     */
    @JsonIgnore
    private long totalPayAmtFen;
    /**
     * 合计应收金额;单位：元
     */
    private BigDecimal totalPayAmt;
    public BigDecimal getTotalPayAmt() {
        return AmtUtil.fenToYuan(this.totalPayAmtFen);
    }


    /**
     * 出账时间
     */
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm")
    private Date outBillTime;

    /**
     * 欠费原因说明
     */
    private String arrearsReason;
    /**
     * 计算违约金截止日期
     */
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    private Date calcBreachDate;

    /**
     * 最后催缴时间
     */
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm")
    private Date lastCallTime;

    private Integer createBillType;

    /**资源代码*/
    private String resourceCode;
    /**客户名称*/
    private String customerName;
    /**合同名称*/
    private String contractName;
    /**园区名称*/
    private String parkName;
    /**楼栋号*/
    private String buildingName;
    /**房间名称*/
    private String houseName;
    /**建筑面积 单位 平方米*/
    private BigDecimal constructionArea;
    /**使用面积 单位 平方米*/
    private BigDecimal useArea;
    /**收费项目*/
    private String feeItemName;
    /**收费标准*/
    private String feeName;
    /**仪表名称*/
    private String meterFullName;
    /**本期读数*/
    private BigDecimal meterReadingNum;
    /**上期读数*/
    private BigDecimal lastMeterReadingNum;
    /**仪表用量*/
    private BigDecimal meterUsage;
    public BigDecimal getMeterUsage() {
        if (this.createBillType != null && this.createBillType == CreateBillTypeEnum.METER.getValue()) {
            return this.billableQuantity;
        }
        return null;
    }

}
