# -*- coding: utf-8 -*-
# iechelle - My Great Project description.
# Copyright (C) 2025 - CEA (Dinil Bose Palakkatharappil
# This file is part of iechelle <https://gitlab.com/dinilbose/iechelle>
# SPDX-License-Identifier: Apache-2.0
"""This module contains the library."""
import configparser
import sys
from typing import Any
from typing import Dict

from loguru import logger

from ._version import __name_soft__

# from py_sas_data_modeler.dm import DataClassFactory
# from py_sas_data_modeler.io import HDF5StorageSasTask


class IechelleLib:
    """The library"""

    def __init__(self, **kwargs):
        # pylint: disable=unused-argument
        path_to_conf = kwargs.get("conf_file", "conf/testmyproject.conf")
        self.__config: configparser.ConfigParser = configparser.ConfigParser()
        self.__config.optionxform = str  # type: ignore
        self.__config.read(path_to_conf)

        self.__directory: str = kwargs.get("directory", "/app")
        self.__level: str = kwargs.get("level", "INFO")
        IechelleLib._parse_level(self.__level)

    @staticmethod
    def _parse_level(level: str):
        """Parse level name and set the rigt level for the logger.
        If the level is not known, the INFO level is set

        Args:
            level (str): level name
        """
        if level == "INFO":
            loguru_level = "INFO"
        elif level == "DEBUG":
            loguru_level = "DEBUG"
        elif level == "WARNING":
            loguru_level = "WARNING"
        elif level == "ERROR":
            loguru_level = "ERROR"
        elif level == "CRITICAL":
            loguru_level = "CRITICAL"
        elif level == "TRACE":
            loguru_level = "TRACE"
        else:
            loguru_level = "INFO"
            logger.log(
                loguru_level,
                f"Unknown level name : {level} - setting level to INFO",
            )

        logger.remove()
        logger.add(sys.stdout, level=loguru_level)

    @property
    def config(self) -> configparser.ConfigParser:
        """The configuration file.

        :getter: Returns the configuration file
        :type: configparser.ConfigParser
        """
        return self.__config

    @property
    def directory(self) -> str:
        """The Base directory.

        :getter: Returns the base directory
        :type: str
        """
        return self.__directory

    @directory.setter
    def directory(self, value: str):
        self.__directory = value

    def sample_function(input: str):
        """
        Decorator to log the inputs and/or outputs of a function, with a configurable log level.

        Args:
            input (bool, optional): Indicates whether to log the inputs of the function. Defaults to `True`.

        Returns:
            Callable: The decorated function that logs its inputs and/or outputs.

        Usage:
            This decorator allows you to log the inputs and/or outputs of a function with a configurable log level.
            It can be used for debugging or monitoring function execution by tracking the values of arguments and results.

        Example usage:
            In this example, only the inputs will be logged at the `DEBUG` level, and the output will not be logged.

        Notes:
            - The `input` and `output` parameters allow fine-grained control over whether the function's arguments or results are logged.

        """
        output = "nothing"
        return output
