"""This module contains the error classes for the chemenv package."""

from __future__ import annotations

__author__ = "David Waroquiers"
__copyright__ = "Copyright 2012, The Materials Project"
__credits__ = "Geoffroy Hautier"
__version__ = "2.0"
__maintainer__ = "David Waroquiers"
__email__ = "david.waroquiers@gmail.com"
__date__ = "Feb 20, 2016"


class AbstractChemenvError(Exception):
    """Abstract class for Chemenv errors."""

    def __init__(self, cls, method, msg):
        """
        Args:
            cls:
            method:
            msg:
        """
        self.cls = cls
        self.method = method
        self.msg = msg

    def __str__(self):
        return f"{self.cls}: {self.method}\n{self.msg!r}"


class NeighborsNotComputedChemenvError(AbstractChemenvError):
    """Neighbors not computed error."""

    def __init__(self, site):
        """
        Args:
            site:
        """
        self.site = site

    def __str__(self):
        return f"The neighbors were not computed for the following site : \n{self.site}"


class EquivalentSiteSearchError(AbstractChemenvError):
    """Equivalent site search error."""

    def __init__(self, site):
        """
        Args:
            site:
        """
        self.site = site

    def __str__(self):
        return f"Equivalent site could not be found for the following site : {self.site}"


class SolidAngleError(AbstractChemenvError):
    """Solid angle error."""

    def __init__(self, cosinus):
        """
        Args:
            cosinus:
        """
        self.cosinus = cosinus

    def __str__(self):
        return f"Value of cosinus ({self.cosinus}) from which an angle should be retrieved is not between -1.0 and 1.0"


class ChemenvError(Exception):
    """Chemenv error."""

    def __init__(self, cls: str, method: str, msg: str):
        """
        Args:
            cls:
            method:
            msg:
        """
        self.cls = cls
        self.method = method
        self.msg = msg

    def __str__(self):
        return f"{self.cls}: {self.method}\n{self.msg}"
