from balderich.utils.code import *

class AuthNoneException(Exception): ...
class AuthNotExistException(Exception): ...
class AuthErrorSignException(Exception): ...
class AuthTimeoutException(Exception): ...
class AuthCalcErrorException(Exception): ...
class AuthRequestFastException(Exception): ...
class RequestPramInvaildException(Exception): ...

class UserNotExistException(Exception): ...
class UserCloseFollowException(Exception): ...
class UserImageNoneException(Exception): ...
class UserImageFormatErrorException(Exception): ...
class UserImageOpenErrorException(Exception): ...
class UserMemoryNotEnoughException(Exception): ...
class UserImageNotExistException(Exception): ...

class ProblemNotExistException(Exception): ...
class ProblemPermissionDeniedException(Exception): ...
class ProblemSheetNotExistException(Exception): ...
class ProblemSheetPermissionDeniedException(Exception): ...

class ContestNotExistException(Exception): ...
class ContestPermissionDeniedException(Exception): ...

class TeamNotExistException(Exception): ...
class TeamPermissionDeniedException(Exception): ...
class TeamNoMemberException(Exception): ...
class TeamMethodPermissionDeniedException(Exception): ...
class TeamProblemNotExistException(Exception): ...
class TeamProblemPermissionDeniedException(Exception): ...
class TeamContestNotExistException(Exception): ...
class TeamContestPermissionDeniedException(Exception): ...

class NotebookArticleNotExistException(Exception): ...
class NotebookArticlePermissionDeniedException(Exception): ...
class UnknownApiException(Exception): ...


_EXCEPTION_MAP = {
    AUTH_NONE: AuthNoneException,
    AUTH_NOT_EXIST: AuthNotExistException,
    AUTH_ERROR_SIGN: AuthErrorSignException,
    AUTH_TIMEOUT: AuthTimeoutException,
    AUTH_CALC_ERROR: AuthCalcErrorException,
    AUTH_REQUEST_FAST: AuthRequestFastException,
    REQUEST_PARAM_INVALID: RequestPramInvaildException,

    USER_NOT_EXIST: UserNotExistException,
    USER_CLOSE_FOLLOW: UserCloseFollowException,
    USER_IMAGE_NONE: UserImageNoneException,
    USER_IMAGE_FORMAT_ERROR: UserImageFormatErrorException,
    USER_IMAGE_OPEN_ERROR: UserImageOpenErrorException,
    USER_MEMORY_NOT_ENOUGH: UserMemoryNotEnoughException,
    USER_IMAGE_NOT_EXIST: UserImageNotExistException,

    PROBLEM_NOT_EXIST: ProblemNotExistException,
    PROBLEM_PERMISSION_DENIED: ProblemPermissionDeniedException,
    PROBLEM_SHEET_NOT_EXIST: ProblemSheetNotExistException,
    PROBLEM_SHEET_PERMISSION_DENIED: ProblemSheetPermissionDeniedException,

    CONTEST_NOT_EXIST: ContestNotExistException,
    CONTEST_PERMISSION_DENIED: ContestPermissionDeniedException,

    TEAM_NOT_EXIST: TeamNotExistException,
    TEAM_PERMISSION_DENIED: TeamPermissionDeniedException,
    TEAM_NO_MEMBER: TeamNoMemberException,
    TEAM_METHOD_PERMISSION_DENIED: TeamMethodPermissionDeniedException,
    TEAM_PROBLEM_NOT_EXIST: TeamProblemNotExistException,
    TEAM_PROBELM_PERMISSION_DENIED: TeamProblemPermissionDeniedException,
    TEAM_CONTEST_NOT_EXIST: TeamContestNotExistException,
    TEAM_CONTEST_PERMISSION_DENIED: TeamContestPermissionDeniedException,

    NOTEBOOK_ARTICLE_NOT_EXIST: NotebookArticleNotExistException,
    NOTEBOOK_ARTICLE_PERMISSION_DENIED: NotebookArticlePermissionDeniedException,
}


def get_exception(code: int, msg: str = '') -> Exception:
    exc = _EXCEPTION_MAP.get(code, UnknownApiException)
    return exc(msg)
