package com.ruoyi.bst.device.domain;

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

import org.springframework.format.annotation.DateTimeFormat;

import com.ruoyi.common.utils.MathUtils;
import com.ruoyi.iot.util.BatUtil;

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

@Data
public class DeviceVO extends Device {

    // 用户
    @ApiModelProperty("直属用户名称")
    private String mchName;
    @ApiModelProperty("直属用户分成")
    private BigDecimal mchPoint;

    // 车型
    @ApiModelProperty("车型名称")
    private String modelName;
    @ApiModelProperty("车型满电电压")
    private BigDecimal modelFullVoltage;
    @ApiModelProperty("车型亏电电压")
    private BigDecimal modelLowVoltage;
    @ApiModelProperty("车型续航")
    private BigDecimal modelFullEndurance;
    @ApiModelProperty("车型是否允许用户打开坐垫锁")
    private Boolean modelEnableSeat;

    // 运营区
    @ApiModelProperty("运营区名称")
    private String areaName;
    @ApiModelProperty("运营区用户分成")
    private BigDecimal areaUserPoint;
    @ApiModelProperty("运营区用户名称")
    private String areaUserName;
    @ApiModelProperty("运营区认证类型")
    private List<String> areaAuthentication;
    @ApiModelProperty("运营区用户ID")
    private Long areaUserId;
    @ApiModelProperty("运营区最低骑行电量")
    private BigDecimal areaUndercharge;
    @ApiModelProperty("运营区代理商分成")
    private BigDecimal areaAgentPoint;
    @ApiModelProperty("运营区代理商ID")
    private Long areaAgentId;
    @ApiModelProperty("运营区代理商名称")
    private String areaAgentName;
    @ApiModelProperty("运营区状态")
    private String areaStatus;
    @ApiModelProperty("运营区营业时间（起始）")
    @DateTimeFormat(pattern = "HH:mm:ss")
    private LocalTime areaTimeStart;
    @ApiModelProperty("运营区营业时间（结束）")
    @DateTimeFormat(pattern = "HH:mm:ss")
    private LocalTime areaTimeEnd;
    @ApiModelProperty("运营区用户响铃寻车范围")
    private BigDecimal areaRingRadius;
    @ApiModelProperty("运营区用户必须响铃寻车范围")
    private Boolean areaRequiredRingRadius;
    @ApiModelProperty("停车点外调度费")
    private BigDecimal areaDispatchFee;
    @ApiModelProperty("运营区外调度费")
    private BigDecimal areaVehicleManagementFee;
    @ApiModelProperty("是否必须停车点还车")
    private Boolean areaParkingReturn;

    // 订单设备
    @ApiModelProperty("当前订单ID")
    private Long orderId;
    @ApiModelProperty("当前订单状态")
    private String orderStatus;
    @ApiModelProperty("当前订单编号")
    private String orderNo;
    @ApiModelProperty("当前订单设备状态")
    private String orderDeviceStatus;
    @ApiModelProperty("当前订单设备开始时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime orderDeviceStartTime;
    @ApiModelProperty("当前订单设备结束时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime orderDeviceEndTime;
    @ApiModelProperty("当前订单用户ID")
    private Long orderUserId;
    @ApiModelProperty("当前订单用户名称")
    private String orderUserName;
    @ApiModelProperty("当前订单用户手机号")
    private String orderUserPhone;

    // 硬件版本
    @ApiModelProperty("硬件版本")
    private String hardwareVersion;
    @ApiModelProperty("硬件版本说明")
    private String hardwareVersionInstructions;

    // 最近一次下单用户
    @ApiModelProperty("最近一次下单用户名称")
    private String lastUserName;
    @ApiModelProperty("最近一次下单用户手机号")
    private String lastUserPhone;

    // 剩余续航（公里）
    public BigDecimal getRemainEndurance() {
        BigDecimal remainEndurance = MathUtils.mulDecimal(getRemainingPower(), getModelFullEndurance());
        return remainEndurance.divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP);
    }

    // 剩余电量百分比
    public BigDecimal getRemainingPower() {
        return BatUtil.calcPowerPoint(getVoltage(), getModelFullVoltage(), getModelLowVoltage());
    }
}
