#  Copyright (C) 2020 The authors of Py-ChemShell
#
#  This file is part of Py-ChemShell.
#
#  Py-ChemShell is free software: you can redistribute it and/or modify
#  it under the terms of the GNU Lesser General Public License as
#  published by the Free Software Foundation, either version 3 of the
#  License, or (at your option) any later version.
#
#  Py-ChemShell is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with Py-ChemShell.  If not, see
#  <http://www.gnu.org/licenses/>.


# we provide users some synonyms
_synons = {
          }

from ..io            import keyword
from ..objects       import options
from ..dl_py2f.utils import objutils

class _Workflows:
    '''Parent class of workflows'''

    _kwargs = {
                'options': options.Options(),
              }

    _internals  = {}

    _inherit    = '_init', '_priorities'

    _init       = '_kwargs', '_internals'

    _priorities = 'theory'


    def run(self, **kwargs):
        ''''''

        return self


    @objutils.init()
    def __init__(self, **kwargs):
        '''Instantiate'''

        # get the keyword arguments that are not parsed to be used later (for the run function)
        self._run_kwargs = keyword.parseKeys(self, **kwargs, strict=False)


    @property
    def __all__(self):
        '''__all__ inherited from base class(es)'''

        # __self_class__ is the children class (i.e. <class Opt>)
        lbuff = list(super().__self_class__._kwargs.keys())

        # __thisclass__ is the base class (i.e. <class Task>)
        lbuff.extend(super().__thisclass__._kwargs)

        __all__ = list(set(lbuff))

        __all__.sort()

        return __all__


    @property
    def options(self):
        '''Options'''

        for key, val in self._kwargs.items():

            # skip attributes in itself
            if key in [ 'options' ]:
                continue

            # complement options._kwargs
            self._options._kwargs.setdefault(key, val)

            # sync the value
            setattr(self._options, key, getattr(self, key))

        return self._options


    @options.setter
    def options(self, val):
        '''Setter of options'''

        self._options = val
