from yta_general_utils.programming.parameter_validator import PythonValidator
from typing import Union


class ErrorMessage:
    """
    Class to encapsulate the different error
    messages we need.
    """

    @staticmethod
    def parameter_is_not_a_class(parameter_name: str):
        return f'The provided "{parameter_name}" parameter is not a class.'
    
    @staticmethod
    def parameter_not_provided(parameter_name: str):
        return f'The parameter "{parameter_name}" was not provided.'
    
    @staticmethod
    def parameter_is_not_string(parameter_name: str):
        return f'The parameter "{parameter_name}" provided is not a string.'
    
    @staticmethod
    def parameter_is_not_boolean(parameter_name: str):
        return f'The "{parameter_name}" parameter is not boolean.'
    
    @staticmethod
    def parameter_is_not_positive_number(parameter_name: str):
        return f'The parameter "{parameter_name}" provided is not a valid and positive number.'
    
    @staticmethod
    def parameter_is_file_that_doesnt_exist(parameter_name: str):
        return f'The "{parameter_name}" parameter provided is not a file that exists.'
    
    @classmethod
    def parameter_is_not_file_of_file_type(parameter_name: str, file_type: 'FileType'):
        return f'The "{parameter_name}" provided is not a {file_type.value} filename.'
    
    @staticmethod
    def parameter_is_not_valid_url(parameter_name: str):
        return f'The provided "{parameter_name}" parameter is not a valid url.'
    
    @staticmethod
    def parameter_is_not_class_of(
        parameter_name: str,
        classes: Union[list[Union[type, str]], str, type]
    ):
        # To list
        classes = (
            [classes]
            if not PythonValidator.is_list(classes) else
            classes
        )

        # To str
        classes = [
            (
                class_item
                if PythonValidator.is_string(class_item) else
                class_item.__name__ # the name of the class
            ) for class_item in classes
        ]

        return f'The provided "{parameter_name}" parameter is not one of these classes: {", ".join(classes)}.'
    
    @staticmethod
    def parameter_is_not_instance_of(
        parameter_name: str,
        classes: Union[list[Union[type, str]], str, type]
    ) -> str:
        """
        Message that indicates that the 'parameter_name'
        is not any of the provided 'classes'.
        """
        # To list
        classes = (
            [classes]
            if not PythonValidator.is_list(classes) else
            classes
        )

        # To str
        classes = [
            (
                class_item
                if PythonValidator.is_string(class_item) else
                class_item.__name__ # the name of the class
            ) for class_item in classes
        ]

        return f'The provided "{parameter_name}" parameter is not an instance of any of these classes: {", ".join(classes)}.'

    @staticmethod
    def parameter_is_not_name_of_ytaenum_class(name: str, enum):
        return f'The provided YTAEnum name "{name}" is not a valid {enum.__class__.__name__} YTAEnum name.'
    
    @staticmethod
    def parameter_is_not_value_of_ytaenum_class(value: any, enum):
        return f'The provided YTAEnum value "{value}" is not a valid {enum.__class__.__name__} YTAEnum value.'
    
    @staticmethod
    def parameter_is_not_name_nor_value_of_ytaenum_class(name_or_value: any, enum):
        return f'The provided YTAEnum name or value "{name_or_value}" is not a valid {enum.__class__.__name__} YTAEnum name or value.'
    
    @staticmethod
    def parameter_is_not_name_nor_value_nor_enum_of_ytaenum_class(name_or_value_or_enum: any, enum):
        return f'The provided YTAEnum name, value or instance "{name_or_value_or_enum}" is not a valid {enum.__class__.__name__} YTAEnum name, value or instance.'
    
   