# Path: core/exceptions.py
# class APIException(exceptions.APIException):
#     """
#     Custom APIException for better uniformity
# 
#     Attributes:
#         message:        the error message explaining the error
#         code:           the short string code error
#         details:        possible serializabled details
#         status_code:    the status code of the response
#         default_detail: the default error message
#         default_code:   the default error code
#     """
#     status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
#     default_detail = "Une erreur interne est survenue, veuillez contactez un administrateur"
#     default_code = 'internal_error'
# 
#     def __init__(self, message: str=None, code: str=None, details: Any=None, status_code: int=None):
#         super().__init__(message, code)
#         self.message = str(self.detail)
#         self.code = self.detail.code
#         self.details = details
#         if status_code is not None:
#             self.status_code = status_code
# 
#     def get_full_details(self) -> dict:
#         """
#         Return the full detailed error for the response
#         """
#         return {
#             'error': type(self).__name__,
#             'message': self.message,
#             'code': self.code,
#             'details': self.details,
#         }
# 
#     def __repr__(self) -> str:
#         return f"<{type(self).__name__} [{self.code}]>"


from rest_framework import status
from core.exceptions import APIException
class OAuthException(APIException):
    """
    Custom OAuth Error for better feedback
    """
    status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
    default_detail = "Une erreur est survenue avec l'authentification, veuillez contactez un administrateur"
    default_code = 'oauth_error'

    @classmethod
    def from_response(cls, response, code: str = None) -> 'OAuthException':
        """
        Create a OAuthException from an OAuth response
        """
        message = response.json().get('message', 'Unknown error')
        details = None

        if 'unauthenticated' in message.lower():
            details = message
            code = code or 'unauthenticated'
            message = "Requête OAuth non authentifié"  # TODO Better message
            return OAuthTokenException(message, code, details)

        return cls(message, code, details)


class OAuthTokenException(OAuthException):

    default_code = 'token_error'



# Path: core/exceptions.py
# class APIException(exceptions.APIException):
#     """
#     Custom APIException for better uniformity
# 
#     Attributes:
#         message:        the error message explaining the error
#         code:           the short string code error
#         details:        possible serializabled details
#         status_code:    the status code of the response
#         default_detail: the default error message
#         default_code:   the default error code
#     """
#     status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
#     default_detail = "Une erreur interne est survenue, veuillez contactez un administrateur"
#     default_code = 'internal_error'
# 
#     def __init__(self, message: str=None, code: str=None, details: Any=None, status_code: int=None):
#         super().__init__(message, code)
#         self.message = str(self.detail)
#         self.code = self.detail.code
#         self.details = details
#         if status_code is not None:
#             self.status_code = status_code
# 
#     def get_full_details(self) -> dict:
#         """
#         Return the full detailed error for the response
#         """
#         return {
#             'error': type(self).__name__,
#             'message': self.message,
#             'code': self.code,
#             'details': self.details,
#         }
# 
#     def __repr__(self) -> str:
#         return f"<{type(self).__name__} [{self.code}]>"


# Path: authentication/exceptions.py
from rest_framework import status
from core.exceptions import APIException

class OAuthException(APIException):
    """
    Custom OAuth Error for better feedback
    """
    status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
    default_detail = "Une erreur est survenue avec l'authentification, veuillez contactez un administrateur"
    default_code = 'oauth_error'

    @classmethod
    def from_response(cls, response, code: str = None) -> 'OAuthException':
        """
        Create a OAuthException from an OAuth response
        """
        message = response.json().get('message', 'Unknown error')
        details = None

        if 'unauthenticated' in message.lower():
            details = message
            code = code or 'unauthenticated'
            message = "Requête OAuth non authentifié"  # TODO Better message
            return OAuthTokenException(message, code, details)

        return cls(message, code, details)


class OAuthTokenException(OAuthException):

    default_code = 'token_error'



class UserTypeValidationError(APIException):