from __future__ import annotations

from typing import Final, TYPE_CHECKING

if TYPE_CHECKING:
    from ..enums import _BaseErrorReference

from ..messages import (
    INPUT_ERROR_MESSAGE,
    MAIN_CHAIN_JSON_ERROR_MESSAGE,
    FALLBACK_CHAIN_JSON_ERROR_MESSAGE,
    MAIN_CHAIN_VALIDATION_ERROR_MESSAGE,
    FALLBACK_CHAIN_VALIDATION_ERROR_MESSAGE,
    MAIN_CHAIN_VALUE_ERROR_MESSAGE,
    FALLBACK_CHAIN_VALUE_ERROR_MESSAGE,
    MAIN_CHAIN_TYPE_ERROR_MESSAGE,
    FALLBACK_CHAIN_TYPE_ERROR_MESSAGE,
    UNKNOWN_ERROR_MESSAGE,
    UNSUPPORTED_LLM_MODEL_ERROR_MESSAGE,
    INVALID_PARSER_TYPE_ERROR_MESSAGE,
    MISSING_PYDANTIC_MODEL_ERROR_MESSAGE,
    MISSING_OUTPUT_KEY_ERROR_MESSAGE,
    INVALID_PARSER_COMBINATION_ERROR_MESSAGE,
    MISSING_PROMPT_VARIABLES_ERROR_MESSAGE,
    INVALID_PROMPT_VARIABLES_ERROR_MESSAGE,
    INVALID_API_KEY_ERROR_MESSAGE,
)

from ..enums import (
    _ChainBuilderErrorReference,
    _ChainComposerErrorReference,
    _ChainWrapperErrorReference,
    _ChainManagerErrorReference,
    _ErrorType,
)

_ERROR_MESSAGE_MAP: Final[dict[_BaseErrorReference, dict[_ErrorType, str]]] = {
    _ChainWrapperErrorReference.INPUT_ERROR: {
        _ErrorType.VALUE_ERROR: INPUT_ERROR_MESSAGE,
    },
    
    _ChainWrapperErrorReference.MAIN_CHAIN_ERROR: {
        _ErrorType.JSON_ERROR: MAIN_CHAIN_JSON_ERROR_MESSAGE,
        _ErrorType.VALIDATION_ERROR: MAIN_CHAIN_VALIDATION_ERROR_MESSAGE,
        _ErrorType.VALUE_ERROR: MAIN_CHAIN_VALUE_ERROR_MESSAGE,
        _ErrorType.TYPE_ERROR: MAIN_CHAIN_TYPE_ERROR_MESSAGE,
        _ErrorType.UNKNOWN_ERROR: UNKNOWN_ERROR_MESSAGE,
    },
    
    _ChainWrapperErrorReference.FALLBACK_CHAIN_ERROR: {
        _ErrorType.JSON_ERROR: FALLBACK_CHAIN_JSON_ERROR_MESSAGE,
        _ErrorType.VALIDATION_ERROR: FALLBACK_CHAIN_VALIDATION_ERROR_MESSAGE,
        _ErrorType.VALUE_ERROR: FALLBACK_CHAIN_VALUE_ERROR_MESSAGE,
        _ErrorType.TYPE_ERROR: FALLBACK_CHAIN_TYPE_ERROR_MESSAGE,
        _ErrorType.UNKNOWN_ERROR: UNKNOWN_ERROR_MESSAGE,
    },
    
    _ChainComposerErrorReference.UNSUPPORTED_LLM_MODEL: {
        _ErrorType.VALUE_ERROR: UNSUPPORTED_LLM_MODEL_ERROR_MESSAGE,
        _ErrorType.UNKNOWN_ERROR: UNKNOWN_ERROR_MESSAGE,
    },
    
    _ChainComposerErrorReference.INVALID_PARSER_TYPE: {
        _ErrorType.VALUE_ERROR: INVALID_PARSER_TYPE_ERROR_MESSAGE,
        _ErrorType.UNKNOWN_ERROR: UNKNOWN_ERROR_MESSAGE,
    },
    
    _ChainComposerErrorReference.MISSING_PYDANTIC_MODEL: {
        _ErrorType.VALUE_ERROR: MISSING_PYDANTIC_MODEL_ERROR_MESSAGE,
        _ErrorType.UNKNOWN_ERROR: UNKNOWN_ERROR_MESSAGE,
    },
    
    _ChainComposerErrorReference.MISSING_OUTPUT_KEY: {
        _ErrorType.VALUE_ERROR: MISSING_OUTPUT_KEY_ERROR_MESSAGE,
        _ErrorType.UNKNOWN_ERROR: UNKNOWN_ERROR_MESSAGE,
    },
    
    _ChainComposerErrorReference.INVALID_PARSER_COMBINATION: {
        _ErrorType.VALUE_ERROR: INVALID_PARSER_COMBINATION_ERROR_MESSAGE,
        _ErrorType.UNKNOWN_ERROR: UNKNOWN_ERROR_MESSAGE,
    },
    
    _ChainComposerErrorReference.MISSING_PROMPT_VARIABLES: {
        _ErrorType.VALUE_ERROR: MISSING_PROMPT_VARIABLES_ERROR_MESSAGE,
        _ErrorType.UNKNOWN_ERROR: UNKNOWN_ERROR_MESSAGE,
    },
    
    _ChainComposerErrorReference.INVALID_PROMPT_VARIABLES: {
        _ErrorType.VALUE_ERROR: INVALID_PROMPT_VARIABLES_ERROR_MESSAGE,
        _ErrorType.UNKNOWN_ERROR: UNKNOWN_ERROR_MESSAGE,
    },
    
    _ChainComposerErrorReference.INVALID_API_KEY: {
        _ErrorType.VALUE_ERROR: INVALID_API_KEY_ERROR_MESSAGE,
        _ErrorType.UNKNOWN_ERROR: UNKNOWN_ERROR_MESSAGE,
    },
}
