package com.ruoyi.ss.transactionBill.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonView;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.constants.DictTypeConstants;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.domain.JsonViewProfile;
import com.ruoyi.common.core.domain.ValidGroup;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillType;
import com.ruoyi.common.pay.Payable;
import com.ruoyi.common.pay.wx.domain.enums.AttachEnums;
import com.ruoyi.system.valid.DictValid;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * 充值记录对象 sm_transaction_bill
 *
 * @author 邱贞招
 * @date 2024-02-21
 */
@Data
public class TransactionBill extends BaseEntity implements Payable
{
    private static final long serialVersionUID = 1L;

    /** 主键 */
    @ApiModelProperty("主键")
    @JsonView(JsonViewProfile.Base.class)
    private Long billId;

    /** 订单编号 */
    @ApiModelProperty("订单编号")
    @JsonView(JsonViewProfile.Base.class)
    private String billNo;

    /** 用户 */
    @Excel(name = "用户")
    @ApiModelProperty("用户id")
    private Long userId;

    /** 类型 */
    @ApiModelProperty("类型：1充值，2提现")
    @JsonView(JsonViewProfile.App.class)
    private String type;

    /** 设备 */
    @Excel(name = "设备")
    @ApiModelProperty("设备id")
    @JsonView(JsonViewProfile.Base.class)
    private Long deviceId;

    @ApiModelProperty("设备编号")
    @NotNull(message = "设备编号不允许为空", groups = {ValidGroup.Recharge.class})
    @JsonView(JsonViewProfile.App.class)
    private String deviceNo;

    /** 商户(到账用户) */
    @Excel(name = "商户(到账用户)")
    @ApiModelProperty("商户(到账用户)id")
    @JsonView(JsonViewProfile.App.class)
    private Long mchId;

    /** 交易金额 */
    @Excel(name = "交易金额")
    @ApiModelProperty("交易金额")
    @NotNull(message = "交易金额不允许为空", groups = {ValidGroup.Recharge.class})
    @Min(value = 0, message = "交易金额不允许小于0", groups = {ValidGroup.Recharge.class})
    @Min(value = 20, message = "申请提现金额不允许小于20", groups = {ValidGroup.Withdraw.class})
    @JsonView(JsonViewProfile.App.class)
    private BigDecimal money;

    /** 实际到账金额 */
    @Excel(name = "商户实际到账金额")
    @ApiModelProperty("商户实际到账金额")
    @JsonView(JsonViewProfile.AppMch.class)
    private BigDecimal arrivalAmount;

    /** 手续费 */
    @Excel(name = "手续费")
    @ApiModelProperty("手续费")
    @Min(value = 0, message = "手续费不允许小于0", groups = { ValidGroup.Withdraw.class})
    @JsonView(JsonViewProfile.AppMch.class)
    private BigDecimal serviceCharge;

    @ApiModelProperty("订单状态：1未支付，2支付成功，3已退款，4已取消")
    @JsonView(JsonViewProfile.App.class)
    private String status;

    @ApiModelProperty("渠道id")
    @JsonView(JsonViewProfile.App.class)
    private Long channelId;

    @ApiModelProperty("到账后余额")
    @JsonView(JsonViewProfile.AppMch.class)
    private BigDecimal afterBalance;

    @ApiModelProperty("支付成功的时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonView(JsonViewProfile.App.class)
    private Date payTime;

    @ApiModelProperty("支付过期时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date expireTime;

    @ApiModelProperty("交易账号（银行卡号、微信openId）")
    @JsonView(JsonViewProfile.App.class)
    private String accountNo;

    @ApiModelProperty("已支付/提现金额")
    @JsonView(JsonViewProfile.App.class)
    private BigDecimal payedAmount;

    @ApiModelProperty("微信商家提现明细id列表")
    private List<String> transferIds;

    @ApiModelProperty("渠道成本")
    private BigDecimal channelCost;

    @ApiModelProperty("设备充值状态，0未充值，1充值成功")
    @JsonView(JsonViewProfile.App.class)
    private String deviceRechargeStatus;

    @ApiModelProperty("套餐id")
    @NotNull(message = "套餐不允许为空", groups = {ValidGroup.Recharge.class})
    @JsonView(JsonViewProfile.App.class)
    private Long suitId;

    @ApiModelProperty("套餐时长（秒）")
    @NotNull(message = "套餐时长不允许为空", groups = {ValidGroup.Recharge.class})
    @JsonView(JsonViewProfile.App.class)
    private Integer suitTime;

    @ApiModelProperty("套餐时长单位")
    @NotBlank(message = "套餐时长单位不允许为空", groups = {ValidGroup.Recharge.class})
    @DictValid(type = DictTypeConstants.TIME_UNIT, message = "非法的套餐时长单位", groups = {ValidGroup.Recharge.class})
    @JsonView(JsonViewProfile.App.class)
    private String suitTimeUnit;

    @ApiModelProperty("套餐开始使用时间")
    @JsonView(JsonViewProfile.App.class)
    private LocalDateTime suitStartTime;

    @ApiModelProperty("套餐结束使用时间")
    @JsonView(JsonViewProfile.App.class)
    private LocalDateTime suitEndTime;

    @ApiModelProperty("套餐到期时间")
    @JsonView(JsonViewProfile.App.class)
    private LocalDateTime suitExpireTime;

    @Excel(name = "套餐开始使用的电量")
    @ApiModelProperty("套餐开始使用的电量")
    @JsonView(JsonViewProfile.App.class)
    private BigDecimal suitStartEle;

    @Excel(name = "套餐结束使用的电量")
    @ApiModelProperty("套餐结束使用的电量")
    @JsonView(JsonViewProfile.App.class)
    private BigDecimal suitEndEle;

    @Excel(name = "套餐收费模式")
    @ApiModelProperty("套餐收费模式")
    @JsonView(JsonViewProfile.App.class)
    private String suitFeeMode;

    @Excel(name = "套餐收费类型")
    @ApiModelProperty("套餐收费类型")
    @JsonView(JsonViewProfile.App.class)
    private String suitFeeType;

    @Excel(name = "套餐档位金额列表")
    @ApiModelProperty("套餐档位金额列表")
    @JsonView(JsonViewProfile.App.class)
    private List<BigDecimal> suitGearAmount;

    @Excel(name = "套餐时段档位列表")
    @ApiModelProperty("套餐时段档位列表")
    @JsonView(JsonViewProfile.App.class)
    private List<Integer> suitGearTime;

    @Excel(name = "套餐金额/押金", readConverterExp = "元=")
    @ApiModelProperty("套餐金额/押金")
    @JsonView(JsonViewProfile.App.class)
    private BigDecimal suitPrice;

    @ApiModelProperty("店铺ID")
    @JsonView(JsonViewProfile.App.class)
    private Long storeId;

    @ApiModelProperty("店铺名称")
    @JsonView(JsonViewProfile.App.class)
    private String storeName;

    @ApiModelProperty("店铺地址")
    @JsonView(JsonViewProfile.App.class)
    private String storeAddress;

    @ApiModelProperty("设备名称")
    @JsonView(JsonViewProfile.App.class)
    private String deviceName;

    @ApiModelProperty("套餐名称")
    @JsonView(JsonViewProfile.App.class)
    private String suitName;

    @ApiModelProperty("设备MAC")
    @JsonView(JsonViewProfile.App.class)
    private String deviceMac;

    @Excel(name = "设备MAC2")
    @ApiModelProperty("设备MAC2")
    @JsonView(JsonViewProfile.App.class)
    private String deviceMac2;

    @Excel(name = "设备产品ID")
    @ApiModelProperty("设备产品ID")
    private String deviceProductId;

    @Excel(name = "设备服务费模式", readConverterExp = "1=-直营模式，2-代理模式")
    @ApiModelProperty("设备服务费模式")
    private String deviceServiceMode;

    @ApiModelProperty("总计退款金额")
    @JsonView(JsonViewProfile.App.class)
    private BigDecimal refundAmount;

    @ApiModelProperty("商户退款金额")
    @JsonView(JsonViewProfile.AppMch.class)
    private BigDecimal refundMchAmount;

    @ApiModelProperty("服务费退款金额")
    @JsonView(JsonViewProfile.AppMch.class)
    private BigDecimal refundServiceAmount;

    @ApiModelProperty("支付凭证")
    @JsonView(JsonViewProfile.AppMch.class)
    private String payPicture;

    @ApiModelProperty("提现方式")
    @JsonView(JsonViewProfile.AppMch.class)
    private String withdrawType;

    @ApiModelProperty("提现审核时的二维码")
    private String offlineImage;

    @Excel(name = "押金支付成功的支付订单ID")
    @ApiModelProperty("押金支付成功的支付订单ID")
    private Long depositPayId;

    @Excel(name = "支付成功的支付订单ID")
    @ApiModelProperty("支付成功的支付订单ID")
    private Long payId;

    @Excel(name = "订单是否开启低功率自动关闭")
    @ApiModelProperty("订单是否开启低功率自动关闭")
    private Boolean suitEnableLowPowerClose;

    @Excel(name = "订单低功率自动关闭值", readConverterExp = "瓦=")
    @ApiModelProperty("订单低功率自动关闭值")
    private BigDecimal suitLowPower;

    @Excel(name = "版本号")
    @ApiModelProperty("版本号")
    private Integer version;

    @Excel(name = "设备关闭状态(1-已关闭，2-未关闭）")
    @ApiModelProperty("设备关闭状态(1-已关闭，2-未关闭）")
    private String closeStatus;

    @Excel(name = "设备关闭状态描述")
    @ApiModelProperty("设备关闭状态描述")
    private String closeResult;

    @Excel(name = "代理商ID")
    @ApiModelProperty("代理商ID")
    private Long agentId;

    @Excel(name = "代理商手机号")
    @ApiModelProperty("代理商手机号")
    private String agentMobile;

    @Excel(name = "套餐是否开启语音播报")
    @ApiModelProperty("套餐是否开启语音播报")
    private Boolean suitEnabledVoid;

    @Excel(name = "套餐语音播报阈值", readConverterExp = "分=钟")
    @ApiModelProperty("套餐语音播报阈值")
    private BigDecimal suitVoidMinute;

    @Excel(name = "套餐语音播报设置结果", readConverterExp = "1=-成功，2-失败")
    @ApiModelProperty("套餐语音播报设置结果")
    private String suitVoidResult;

    @Excel(name = "套餐语音播报设置结果描述")
    @ApiModelProperty("套餐语音播报设置结果描述")
    private String suitVoidMsg;

    @Excel(name = "套餐押金", readConverterExp = "元=")
    @ApiModelProperty("套餐押金")
    @JsonView(JsonViewProfile.App.class)
    private BigDecimal suitDeposit;

    @Excel(name = "设备开启状态描述")
    @ApiModelProperty("设备开启状态描述")
    private String openMsg;

    @Excel(name = "用户手机号")
    @ApiModelProperty("用户手机号")
    @JsonView(JsonViewProfile.App.class)
    private String userMobile;

    @Excel(name = "商户是否展示用户手机号")
    @ApiModelProperty("商户是否展示用户手机号")
    private Boolean mchShowMobile;

    @Excel(name = "商户展示手机号价格")
    @ApiModelProperty("商户展示手机号价格")
    private BigDecimal mchShowMobilePrice;

    @Excel(name = "商户展示手机号缴费状态", readConverterExp = "1=-待缴费，2-已缴费")
    @ApiModelProperty("商户展示手机号缴费状态")
    private String mchShowMobileStatus;

    /**
     * 获取价格（分）
     */
    @Override
    public BigDecimal payableFen() {
        return money.multiply(BigDecimal.valueOf(100));
    }

    /**
     * 获取描述
     */
    @Override
    public String payableDescription() {
        return TransactionBillType.parse(type).getDescription();
    }

    /**
     * 获取附加信息
     */
    @Override
    public String payableAttach() {
        return AttachEnums.TRANSACTION_BILL.getAttach();
    }

    /**
     * 获取外部订单号
     */
    @Override
    public String payableOutTradeNo() {
        return billNo;
    }

    /**
     * 获取微信openId
     */
    @Override
    public String payableOpenId() {
        return accountNo;
    }
}
