package org.dromara.member.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serial;

/**
 * 设备相关异常
 *
 * @author pengles
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class DeviceException extends RuntimeException {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private Integer code;

    /**
     * 错误信息
     */
    private String message;

    public DeviceException(String message) {
        super(message);
        this.message = message;
        this.code = 400;
    }

    public DeviceException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public DeviceException(String message, Throwable cause) {
        super(message, cause);
        this.message = message;
        this.code = 400;
    }

    /**
     * 设备已绑定异常
     */
    public static DeviceException deviceAlreadyBound(String deviceInfo) {
        return new DeviceException(4001, "设备已绑定: " + deviceInfo);
    }

    /**
     * 设备不存在异常
     */
    public static DeviceException deviceNotFound(Long deviceId) {
        return new DeviceException(4002, "设备不存在: " + deviceId);
    }

    /**
     * 设备绑定失败异常
     */
    public static DeviceException bindFailed(String reason) {
        return new DeviceException(4003, "设备绑定失败: " + reason);
    }

    /**
     * 设备解绑失败异常
     */
    public static DeviceException unbindFailed(String reason) {
        return new DeviceException(4004, "设备解绑失败: " + reason);
    }

    /**
     * 设备状态异常
     */
    public static DeviceException invalidStatus(String status) {
        return new DeviceException(4005, "设备状态异常: " + status);
    }

    /**
     * 推送令牌无效异常
     */
    public static DeviceException invalidPushToken(String token) {
        return new DeviceException(4006, "推送令牌无效: " + token);
    }

    /**
     * 设备数量超限异常
     */
    public static DeviceException deviceLimitExceeded(int limit) {
        return new DeviceException(4007, "设备数量超出限制，最多允许绑定 " + limit + " 台设备");
    }
}