package com.kym.common.exception;

import com.kym.common.constant.ResponseEnum;

/**
 * 充电业务异常
 * 用于处理充电过程中的各类业务异常
 *
 * @author skyline
 */
public class ChargeException extends BusinessException {

    private static final long serialVersionUID = 1L;

    public ChargeException(String message) {
        super(ResponseEnum.HTTP_STATUS_500.getCode(), message);
    }

    public ChargeException(Integer code, String message) {
        super(code, message);
    }

    public ChargeException(ResponseEnum responseEnum) {
        super(responseEnum);
    }

    public ChargeException(ResponseEnum responseEnum, Throwable cause) {
        super(responseEnum.getCode(), responseEnum.getMessage());
        this.initCause(cause);
    }

    /**
     * 充电枪离线异常
     */
    public static class ConnectorOfflineException extends ChargeException {
        public ConnectorOfflineException(String connectorId) {
            super("充电枪" + connectorId + "离线，请稍后重试");
        }
    }

    /**
     * 余额不足异常
     */
    public static class InsufficientBalanceException extends ChargeException {
        private final Double balance;

        public InsufficientBalanceException(Double balance) {
            super("用户余额不足，当前余额：" + balance);
            this.balance = balance;
        }

        public Double getBalance() {
            return balance;
        }
    }

    /**
     * 预约冲突异常
     */
    public static class BookingConflictException extends ChargeException {
        public BookingConflictException(String message) {
            super(message);
        }
    }

    /**
     * 设备状态异常
     */
    public static class EquipmentStatusException extends ChargeException {
        public EquipmentStatusException(String equipmentId, String status) {
            super("设备" + equipmentId + "状态异常：" + status);
        }
    }
}
