package dev.lions.user.manager.service.exception;

/**
 * Exception levée lorsqu'une erreur survient lors de l'appel au service Keycloak.
 * 
 * @author Lions User Manager Team
 * @version 1.0
 */
public class KeycloakServiceException extends RuntimeException {

    private final int httpStatus;
    private final String serviceName;

    public KeycloakServiceException(String message) {
        super(message);
        this.httpStatus = 0;
        this.serviceName = "Keycloak";
    }

    public KeycloakServiceException(String message, Throwable cause) {
        super(message, cause);
        this.httpStatus = 0;
        this.serviceName = "Keycloak";
    }

    public KeycloakServiceException(String message, int httpStatus) {
        super(message);
        this.httpStatus = httpStatus;
        this.serviceName = "Keycloak";
    }

    public KeycloakServiceException(String message, int httpStatus, Throwable cause) {
        super(message, cause);
        this.httpStatus = httpStatus;
        this.serviceName = "Keycloak";
    }

    public int getHttpStatus() {
        return httpStatus;
    }

    public String getServiceName() {
        return serviceName;
    }

    /**
     * Exception spécifique pour les erreurs de connexion (service indisponible)
     */
    public static class ServiceUnavailableException extends KeycloakServiceException {
        public ServiceUnavailableException(String message) {
            super("Service Keycloak indisponible: " + message);
        }

        public ServiceUnavailableException(String message, Throwable cause) {
            super("Service Keycloak indisponible: " + message, cause);
        }
    }

    /**
     * Exception spécifique pour les erreurs de timeout
     */
    public static class TimeoutException extends KeycloakServiceException {
        public TimeoutException(String message) {
            super("Timeout lors de l'appel au service Keycloak: " + message);
        }

        public TimeoutException(String message, Throwable cause) {
            super("Timeout lors de l'appel au service Keycloak: " + message, cause);
        }
    }
}

