package com.ruoyi.bst.order.domain;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

import com.ruoyi.bst.order.domain.vo.OrderCalcPreRideFeeVO;
import com.ruoyi.bst.order.utils.OrderUtil;
import com.ruoyi.bst.orderDevice.domain.OrderDeviceVO;
import com.ruoyi.common.utils.MathUtils;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public class OrderVO extends Order {

    // 订单设备
    @ApiModelProperty("当前设备ID")
    private Long deviceId;
    @ApiModelProperty("当前设备MAC")
    private String deviceMac;
    @ApiModelProperty("当前设备SN")
    private String deviceSn;
    @ApiModelProperty("当前设备车牌号")
    private String deviceVehicleNum;
    @ApiModelProperty("当前设备状态")
    private String deviceStatus;
    @ApiModelProperty("当前设备所属用户ID")
    private Long deviceMchId;
    @ApiModelProperty("结束子区域ID")
    private Long endAreaSubId;
    @ApiModelProperty("结束子区域名称")
    private String endAreaSubName;
    @ApiModelProperty("还车定位方式")
    private String returnMode;
    @ApiModelProperty("订单设备列表")
    private List<OrderDeviceVO> orderDeviceList;

    // 运营区
    @ApiModelProperty("运营区名称")
    private String areaName;

    // 用户
    @ApiModelProperty("用户名称")
    private String userName;
    @ApiModelProperty("用户手机号")
    private String userPhone;

    // 押金支付
    @ApiModelProperty("支付单号")
    private String payNo;
    @ApiModelProperty("已支付金额")
    private BigDecimal payedAmount;
    @ApiModelProperty("支付已退款金额")
    private BigDecimal payRefunded;
    @ApiModelProperty("支付退款中金额")
    private BigDecimal payRefunding;
    @ApiModelProperty("支付时间")
    private LocalDateTime payTime;
    @ApiModelProperty("支付渠道名称")
    private String payChannelName;
    @ApiModelProperty("支付渠道ID")
    private Long payChannelId;
    @ApiModelProperty("自动退款金额")
    private BigDecimal payAutoRefund;
    @ApiModelProperty("管理员退款金额")
    private BigDecimal payAdminRefund;
    @ApiModelProperty("支付APPID")
    private Long payAppId;

    // 骑行支付
    @ApiModelProperty("骑行支付金额")
    private BigDecimal ridePayAmount;
    @ApiModelProperty("骑行支付已退款金额")
    private BigDecimal ridePayRefunded;
    @ApiModelProperty("骑行支付退款中金额")
    private BigDecimal ridePayRefunding;

    // 剩余可抵扣押金
    @ApiModelProperty("剩余可抵扣押金")
    private BigDecimal depositDeductRemain;

    // 实收骑行费（含退款）
    public BigDecimal getActualReceivedRidingFee() {
        return MathUtils.subtractDecimal(this.getActualRidingFee(), this.getRidingRefund());
    }

    // 实收调度费（含退款）
    public BigDecimal getActualReceivedDispatchFee() {
        return MathUtils.subtractDecimal(this.getActualDispatchFee(), this.getDispatchRefund());
    }

    // 实收管理费（含退款）
    public BigDecimal getActualReceivedManageFee() {
        return MathUtils.subtractDecimal(this.getActualManageFee(), this.getManageRefund());
    }

    // 实收车损费（含退款）
    public BigDecimal getActualReceivedDeductionFee() {
        return MathUtils.subtractDecimal(this.getActualDeductionFee(), this.getDeductionRefund());
    }
    
    // 允许自动退款金额
    public BigDecimal getCanAutoRefundAmount() {
        return OrderUtil.calcCanAutoRefundAmount(this);
    }
    
    // 总退款金额
    public BigDecimal getTotalRefundAmount() {
        return MathUtils.addDecimal(this.getPayRefunded(), this.getPayRefunding(), this.getRidePayRefunded(), this.getRidePayRefunding());
    }

    // 实收金额（减去退款）
    public BigDecimal getActualReceivedAmount() {
        return MathUtils.subtractDecimal(this.getActualAmount(), this.getAdminRefundAmount());
    }

    // 总优惠金额
    public BigDecimal getTotalDiscountAmount() {
        return this.getRidingDiscount();
    }

    // 预估骑行费
    public OrderCalcPreRideFeeVO getPreRideFee() {
        return OrderUtil.calcRideFee(this, LocalDateTime.now());
    }
}
