from typing import Any


class ComponentException(Exception):
    """Exception to re-raise exceptions with error code raised in the component code."""

    __is_hetida_designer_exception__ = True

    def __init__(
        self,
        *args: Any,
        error_code: int | str = "",
        extra_information: dict | None = None,
        **kwargs: Any,
    ) -> None:
        if not isinstance(error_code, int | str):
            raise ValueError("The ComponentException.error_code must be int or string!")
        self.error_code = error_code
        self.extra_information = extra_information
        super().__init__(*args, **kwargs)


class HelperException(Exception):
    """Exception to re-raise exceptions with error code raised in the code of the hdhelpers
    package."""

    __is_hetida_designer_exception__ = True

    def __init__(
        self,
        *args: Any,
        error_code: int | str = "",
        extra_information: dict | None = None,
        **kwargs: Any,
    ) -> None:
        if not isinstance(error_code, int | str):
            raise ValueError("The HelperException.error_code must be int or string!")
        self.error_code = error_code
        self.extra_information = extra_information
        super().__init__(*args, **kwargs)


class InsufficientPlottingData(ComponentException):
    """A plot component has insufficient data to generate a meaningful plot

    This exception class should be used when custom plots generated by hetida
    designer are integrated in other frontends. This allows the frontend to
    handle the case of e.g. no data to show in a sensible way, surpressing an
    empty plot and showing an adequate message instead.
    """
