from ._utils import api_util
from .Bases import Iterable
from dss import LineUnits


class ILineGeometries(Iterable):
    """
    LineGeometry objects

    **(API Extension)**
    """

    __name__ = "LineGeometries"
    _api_prefix = "LineGeometries"
    __slots__ = []
    _columns = [
        "Name",
        "Idx",
        "Nconds",
        "Phases",
        "RhoEarth",
        "Reduce",
        "Units",
        "Conductors",
        "Xcoords",
        "Ycoords",
        # "Rmatrix",
        # "Xmatrix",
        # "Zmatrix",
        "NormAmps",
        "EmergAmps",
    ]

    def Conductors(self):
        """Array of strings with names of all conductors in the active LineGeometry object"""
        return self._lib.LineGeometries_Get_Conductors()

    def EmergAmps(self, *args):
        """Emergency ampere rating"""
        # Getter
        if len(args) == 0:
            return self._lib.LineGeometries_Get_EmergAmps()

        # Setter
        (Value,) = args
        self._lib.LineGeometries_Set_EmergAmps(Value)

    def NormAmps(self, *args):
        """Normal ampere rating"""
        # Getter
        if len(args) == 0:
            return self._lib.LineGeometries_Get_NormAmps()

        # Setter
        (Value,) = args
        self._lib.LineGeometries_Set_NormAmps(Value)

    def RhoEarth(self, *args):
        # Getter
        if len(args) == 0:
            return self._lib.LineGeometries_Get_RhoEarth()

        # Setter
        (Value,) = args
        self._lib.LineGeometries_Set_RhoEarth(Value)

    def Reduce(self, *args):
        # Getter
        if len(args) == 0:
            return self._lib.LineGeometries_Get_Reduce()

        # Setter
        (Value,) = args
        self._lib.LineGeometries_Set_Reduce(Value)

    def Phases(self, *args):
        """Number of Phases"""
        # Getter
        if len(args) == 0:
            return self._lib.LineGeometries_Get_Phases()

        # Setter
        (Value,) = args
        self._lib.LineGeometries_Set_Phases(Value)

    def Rmatrix(self, Frequency, Length, Units):
        """Resistance matrix, ohms"""
        return self._lib.LineGeometries_Get_Rmatrix_GR(Frequency, Length, Units)

    def Xmatrix(self, Frequency, Length, Units):
        """Reactance matrix, ohms"""
        return self._lib.LineGeometries_Get_Xmatrix_GR(Frequency, Length, Units)

    def Zmatrix(self, Frequency, Length, Units):
        """Complex impedance matrix, ohms"""
        return self._lib.LineGeometries_Get_Zmatrix_GR(Frequency, Length, Units)

    def Cmatrix(self, Frequency, Length, Units):
        """Capacitance matrix, nF"""
        return self._lib.LineGeometries_Get_Cmatrix_GR(Frequency, Length, Units)

    def Units(self, *args):
        # Getter
        if len(args) == 0:
            return [LineUnits(unit) for unit in self._lib.LineGeometries_Get_Units_GR()]

        # Setter
        (Value,) = args
        Value, ValuePtr, ValueCount = self._prepare_int32_array(Value)
        self._lib.LineGeometries_Set_Units(ValuePtr, ValueCount)

    def Xcoords(self, *args):
        """Get/Set the X (horizontal) coordinates of the conductors"""
        # Getter
        if len(args) == 0:
            return self._lib.LineGeometries_Get_Xcoords_GR()

        # Setter
        (Value,) = args
        Value, ValuePtr, ValueCount = self._prepare_float64_array(Value)
        self._lib.LineGeometries_Set_Xcoords(ValuePtr, ValueCount)

    def Ycoords(self, *args):
        """Get/Set the Y (vertical/height) coordinates of the conductors"""
        # Getter
        if len(args) == 0:
            return self._lib.LineGeometries_Get_Ycoords_GR()

        # Setter
        (Value,) = args
        Value, ValuePtr, ValueCount = self._prepare_float64_array(Value)
        self._lib.LineGeometries_Set_Ycoords(ValuePtr, ValueCount)

    def Nconds(self, *args):
        """Number of conductors in this geometry. Default is 3. Triggers memory allocations. Define first!"""
        # Getter
        if len(args) == 0:
            return self._lib.LineGeometries_Get_Nconds()

        # Setter
        (Value,) = args
        self._lib.LineGeometries_Set_Nconds(Value)


_LineGeometries = ILineGeometries(api_util)

# For backwards compatibility, bind to the default instance
AllNames = _LineGeometries.AllNames
Cmatrix = _LineGeometries.Cmatrix
Conductors = _LineGeometries.Conductors
Count = _LineGeometries.Count
EmergAmps = _LineGeometries.EmergAmps
First = _LineGeometries.First
Idx = _LineGeometries.Idx
Name = _LineGeometries.Name
Nconds = _LineGeometries.Nconds
Next = _LineGeometries.Next
NormAmps = _LineGeometries.NormAmps
Phases = _LineGeometries.Phases
Reduce = _LineGeometries.Reduce
RhoEarth = _LineGeometries.RhoEarth
Rmatrix = _LineGeometries.Rmatrix
Units = _LineGeometries.Units
Xcoords = _LineGeometries.Xcoords
Xmatrix = _LineGeometries.Xmatrix
Ycoords = _LineGeometries.Ycoords
Zmatrix = _LineGeometries.Zmatrix
_columns = _LineGeometries._columns
__all__ = [
    "AllNames",
    "Cmatrix",
    "Conductors",
    "Count",
    "EmergAmps",
    "First",
    "Idx",
    "Name",
    "Nconds",
    "Next",
    "NormAmps",
    "Phases",
    "Reduce",
    "RhoEarth",
    "Rmatrix",
    "Units",
    "Xcoords",
    "Xmatrix",
    "Ycoords",
    "Zmatrix",
]
