from .errors_dictionary import ErrorMessages


class AlchemyError:
    ERRORS_DICT = {
        "100": "HTTP_100_CONTINUE",
        "101": "HTTP_101_SWITCHING_PROTOCOLS",
        "102": "HTTP_102_PROCESSING",
        "103": "HTTP_103_EARLY_HINTS",
        "200": "HTTP_200_OK",
        "201": "HTTP_201_CREATED",
        "202": "HTTP_202_ACCEPTED",
        "203": "HTTP_203_NON_AUTHORITATIVE_INFORMATION",
        "204": "HTTP_204_NO_CONTENT",
        "205": "HTTP_205_RESET_CONTENT",
        "206": "HTTP_206_PARTIAL_CONTENT",
        "207": "HTTP_207_MULTI_STATUS",
        "208": "HTTP_208_ALREADY_REPORTED",
        "226": "HTTP_226_IM_USED",
        "300": "HTTP_300_MULTIPLE_CHOICES",
        "301": "HTTP_301_MOVED_PERMANENTLY",
        "302": "HTTP_302_FOUND",
        "303": "HTTP_303_SEE_OTHER",
        "304": "HTTP_304_NOT_MODIFIED",
        "305": "HTTP_305_USE_PROXY",
        "306": "HTTP_306_RESERVED",
        "307": "HTTP_307_TEMPORARY_REDIRECT",
        "308": "HTTP_308_PERMANENT_REDIRECT",
        "400": "HTTP_400_BAD_REQUEST",
        "401": "HTTP_401_UNAUTHORIZED",
        "402": "HTTP_402_PAYMENT_REQUIRED",
        "403": "HTTP_403_FORBIDDEN",
        "404": "HTTP_404_NOT_FOUND",
        "405": "HTTP_405_METHOD_NOT_ALLOWED",
        "406": "HTTP_406_NOT_ACCEPTABLE",
        "407": "HTTP_407_PROXY_AUTHENTICATION_REQUIRED",
        "408": "HTTP_408_REQUEST_TIMEOUT",
        "409": "HTTP_409_CONFLICT",
        "410": "HTTP_410_GONE",
        "411": "HTTP_411_LENGTH_REQUIRED",
        "412": "HTTP_412_PRECONDITION_FAILED",
        "413": "HTTP_413_REQUEST_ENTITY_TOO_LARGE",
        "414": "HTTP_414_REQUEST_URI_TOO_LONG",
        "415": "HTTP_415_UNSUPPORTED_MEDIA_TYPE",
        "416": "HTTP_416_REQUESTED_RANGE_NOT_SATISFIABLE",
        "417": "HTTP_417_EXPECTATION_FAILED",
        "418": "HTTP_418_IM_A_TEAPOT",
        "421": "HTTP_421_MISDIRECTED_REQUEST",
        "422": "HTTP_422_UNPROCESSABLE_ENTITY",
        "423": "HTTP_423_LOCKED",
        "424": "HTTP_424_FAILED_DEPENDENCY",
        "426": "HTTP_426_UPGRADE_REQUIRED",
        "428": "HTTP_428_PRECONDITION_REQUIRED",
        "429": "HTTP_429_TOO_MANY_REQUESTS",
        "431": "HTTP_431_REQUEST_HEADER_FIELDS_TOO_LARGE",
        "451": "HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS",
        "500": "HTTP_500_INTERNAL_SERVER_ERROR",
    }
    ERRORS_KEYS = {
        "delete": "DeletedRecord",
        "update": "UpdatedRecord",
        "create": "CreatedRecord",
        "list": "ListedRecords",
        "not_found": "RecordNotFound",
        "already_exist": "AlreadyExists",
        "not_deleted": "RecordNotDeleted",
        "not_updated": "RecordNotUpdated",
        "not_created": "RecordNotCreated",
        "not_listed": "RecordsNotListed",
        "not_confirm": "IsNotConfirmed",
    }

    def __init__(self, lang):
        self.lang = lang

    def retrieve_error_needs(self, data, status_code, error_case, message_key):
        return dict(
            status_code=self.ERRORS_DICT[status_code],
            error_case=self.ERRORS_KEYS[error_case],
            data=data,
            message=ErrorMessages.get_message(message_key, self.lang),
        )


alchemy_error = AlchemyError(lang="")
