# -*- coding: utf-8

"""Module for custom component groups.

It is possible to create subsystems of component groups in tespy. The subsystem
class is the base class for custom subsystems.


This file is part of project TESPy (github.com/oemof/tespy). It's copyrighted
by the contributors recorded in the version control history of the file,
available from its original location tespy/components/subsystems.py

SPDX-License-Identifier: MIT
"""

import logging

# %%


class subsystem:
    r"""
    Class subsystem is the base class of all TESPy subsystems.

    Parameters
    ----------
    label : str
        The label of the subsystem.

    Example
    -------
    Basic example for a setting up a tespy.components.subsystems.subsystem
    object. This example does not run a tespy calculation!

    >>> from tespy.components import subsystem
    >>> mysub = subsystem('mySubsystem')
    >>> type(mysub)
    <class 'tespy.components.subsystems.subsystem'>
    >>> mysub.get_attr('label')
    'mySubsystem'
    """

    def __init__(self, label):

        if not isinstance(label, str):
            msg = 'Subsystem label must be of type str!'
            logging.error(msg)
            raise ValueError(msg)

        elif len([x for x in [';', ', ', '.'] if x in label]) > 0:
            msg = 'Can\'t use ' + str([';', ', ', '.']) + ' in label.'
            logging.error(msg)
            raise ValueError(msg)
        else:
            self.label = label

        self.comps = {}
        self.conns = {}
        self.create_comps()
        self.create_conns()

    def get_attr(self, key):
        r"""
        Get the value of a subsystem's attribute.

        Parameters
        ----------
        key : str
            The attribute you want to retrieve.

        Returns
        -------
        out :
            Value of specified attribute.
        """
        if key in self.__dict__:
            return self.__dict__[key]
        else:
            msg = 'Subsystem ' + self.label + ' has no attribute ' + key + '.'
            logging.error(msg)
            raise KeyError(msg)

    def create_comps(self):
        """Create the subsystem's components."""
        return

    def create_conns(self):
        """Create the subsystem's connections."""
        return

[((47, 12, 47, 30), 'logging.error', 'logging.error', ({(47, 26, 47, 29): 'msg'}, {}), '(msg)', False, 'import logging\n'), ((80, 12, 80, 30), 'logging.error', 'logging.error', ({(80, 26, 80, 29): 'msg'}, {}), '(msg)', False, 'import logging\n'), ((52, 12, 52, 30), 'logging.error', 'logging.error', ({(52, 26, 52, 29): 'msg'}, {}), '(msg)', False, 'import logging\n')]