import pandas as pd


class Aqualog:
    """The Horiba Aqualog Simultaneous Absorbance-Fluorescence Spectrometer."""

    manufacturer = "Horiba"
    """Name of Manufacturer."""

    name = "aqualog"
    """Name of Instrument."""

    supported_models = ["Aqualog-880-C"]
    """List of supported models."""

    def __init__(self, model, sn=None):
        """
        Args:
            model (str): The model name of the instrument.
            sn (str or int, optional): The serial number of the instrument.
                Defaults to None.
        """
        self.model = model
        self.sn = sn

    @staticmethod
    def load_eem(filepath):
        """Loads an Excitation Emission Matrix which is generated by the instrument.

        Args:
            filepath (str): The filepath of the data file.

        Returns:
            pandas.DataFrame: An Excitation Emission Matrix.
        """
        eem_df = pd.read_csv(filepath, sep="\t", index_col=0)
        eem_df.dropna(how="all", axis=1, inplace=True)
        eem_df.dropna(how="all", axis=0, inplace=True)
        eem_df.columns = eem_df.columns.astype(float)
        eem_df = eem_df.sort_index(axis=0)
        eem_df = eem_df.sort_index(axis=1)
        eem_df.index.name = "emission_wavelength"
        return eem_df

    @staticmethod
    def load_absorbance(filepath):
        """Loads an absorbance spectrum which is generated by the instrument.

        Args:
            filepath (str): The filepath of the data file.

        Returns:
            pandas.DataFrame: An absorbance spectrum.
        """
        absorb = pd.read_csv(filepath, sep="\t", index_col=0, header=0, skiprows=[1, 2])
        absorb = absorb[["Abs"]]
        absorb.rename(columns={"Abs": "absorbance"}, inplace=True)
        absorb["absorbance"] = absorb["absorbance"].apply(
            pd.to_numeric, errors="coerce"
        )
        absorb.fillna(0, inplace=True)
        absorb.index = absorb.index.astype("float64")
        absorb = absorb.sort_index()
        absorb.index.name = "wavelength"
        return absorb

    @staticmethod
    def load_water_raman(filepath):
        """Loads a water Raman spectrum which is generated by the instrument.

        Args:
            filepath (str): The filepath of the data file.

        Raises:
            NotImplementedError: On the TODO list...
        """
        raise NotImplementedError()

    @staticmethod
    def load_spectral_corrections():
        """TODO - Should load instrument specific spectral corrections which will
        be used in data preprocessing.

        Raises:
            NotImplementedError: On the TODO list...
        """
        raise NotImplementedError()
