#!/usr/bin/env python3

"""Phosphor DBus Monitor YAML parser and code generator.

The parser workflow is broken down as follows:
  1 - Import YAML files as native python type(s) instance(s).
  2 - Create an instance of the Everything class from the
        native python type instance(s) with the Everything.load
        method.
  3 - The Everything class constructor orchestrates conversion of the
        native python type(s) instances(s) to render helper types.
        Each render helper type constructor imports its attributes
        from the native python type(s) instances(s).
  4 - Present the converted YAML to the command processing method
        requested by the script user.
"""

import os
import sys
from argparse import ArgumentParser

import mako.lookup
import sdbusplus.property
import yaml
from sdbusplus.namedelement import NamedElement
from sdbusplus.renderer import Renderer


class InvalidConfigError(Exception):
    """General purpose config file parsing error."""

    def __init__(self, path, msg):
        """Display configuration file with the syntax
        error and the error message."""

        self.config = path
        self.msg = msg


class NotUniqueError(InvalidConfigError):
    """Within a config file names must be unique.
    Display the config file with the duplicate and
    the duplicate itself."""

    def __init__(self, path, cls, *names):
        fmt = 'Duplicate {0}: "{1}"'
        super(NotUniqueError, self).__init__(
            path, fmt.format(cls, " ".join(names))
        )


def get_index(objs, cls, name, config=None):
    """Items are usually rendered as C++ arrays and as
    such are stored in python lists.  Given an item name
    its class, and an optional config file filter, find
    the item index."""

    for i, x in enumerate(objs.get(cls, [])):
        if config and x.configfile != config:
            continue
        if x.name != name:
            continue

        return i
    raise InvalidConfigError(config, 'Could not find name: "{0}"'.format(name))


def exists(objs, cls, name, config=None):
    """Check to see if an item already exists in a list given
    the item name."""

    try:
        get_index(objs, cls, name, config)
    except Exception:
        return False

    return True


def add_unique(obj, *a, **kw):
    """Add an item to one or more lists unless already present,
    with an option to constrain the search to a specific config file."""

    for container in a:
        if not exists(container, obj.cls, obj.name, config=kw.get("config")):
            container.setdefault(obj.cls, []).append(obj)


class Cast(object):
    """Decorate an argument by casting it."""

    def __init__(self, cast, target):
        """cast is the cast type (static, const, etc...).
        target is the cast target type."""
        self.cast = cast
        self.target = target

    def __call__(self, arg):
        return "{0}_cast<{1}>({2})".format(self.cast, self.target, arg)


class Literal(object):
    """Decorate an argument with a literal operator."""

    integer_types = ["int16", "int32", "int64", "uint16", "uint32", "uint64"]

    def __init__(self, type):
        self.type = type

    def __call__(self, arg):
        if "uint" in self.type:
            arg = "{0}ull".format(arg)
        elif "int" in self.type:
            arg = "{0}ll".format(arg)

        if self.type in self.integer_types:
            return Cast("static", "{0}_t".format(self.type))(arg)
        elif self.type == "byte":
            return Cast("static", "uint8_t")(arg)
        elif self.type == "double":
            return Cast("static", "double")(arg)

        if self.type == "string":
            return "{0}s".format(arg)

        return arg


class FixBool(object):
    """Un-capitalize booleans."""

    def __call__(self, arg):
        return "{0}".format(arg.lower())


class Quote(object):
    """Decorate an argument by quoting it."""

    def __call__(self, arg):
        return '"{0}"'.format(arg)


class Argument(NamedElement, Renderer):
    """Define argument type interface."""

    def __init__(self, **kw):
        self.type = kw.pop("type", None)
        super(Argument, self).__init__(**kw)

    def argument(self, loader, indent):
        raise NotImplementedError


class TrivialArgument(Argument):
    """Non-array type arguments."""

    def __init__(self, **kw):
        self.value = kw.pop("value")
        self.decorators = kw.pop("decorators", [])
        if kw.get("type", None):
            self.decorators.insert(0, Literal(kw["type"]))
        if kw.get("type", None) == "string":
            self.decorators.insert(0, Quote())
        if kw.get("type", None) == "boolean":
            self.decorators.insert(0, FixBool())

        super(TrivialArgument, self).__init__(**kw)

    def argument(self, loader, indent):
        a = str(self.value)
        for d in self.decorators:
            a = d(a)

        return a


class Metadata(Argument):
    """Metadata type arguments."""

    def __init__(self, **kw):
        self.value = kw.pop("value")
        self.decorators = kw.pop("decorators", [])
        if kw.get("type", None) == "string":
            self.decorators.insert(0, Quote())

        super(Metadata, self).__init__(**kw)

    def argument(self, loader, indent):
        a = str(self.value)
        for d in self.decorators:
            a = d(a)

        return a


class OpArgument(Argument):
    """Operation type arguments."""

    def __init__(self, **kw):
        self.op = kw.pop("op")
        self.bound = kw.pop("bound")
        self.decorators = kw.pop("decorators", [])
        if kw.get("type", None):
            self.decorators.insert(0, Literal(kw["type"]))
        if kw.get("type", None) == "string":
            self.decorators.insert(0, Quote())
        if kw.get("type", None) == "boolean":
            self.decorators.insert(0, FixBool())

        super(OpArgument, self).__init__(**kw)

    def argument(self, loader, indent):
        a = str(self.bound)
        for d in self.decorators:
            a = d(a)

        return a


class Indent(object):
    """Help templates be depth agnostic."""

    def __init__(self, depth=0):
        self.depth = depth

    def __add__(self, depth):
        return Indent(self.depth + depth)

    def __call__(self, depth):
        """Render an indent at the current depth plus depth."""
        return 4 * " " * (depth + self.depth)


class ConfigEntry(NamedElement):
    """Base interface for rendered items."""

    def __init__(self, *a, **kw):
        """Pop the configfile/class/subclass keywords."""

        self.configfile = kw.pop("configfile")
        self.cls = kw.pop("class")
        self.subclass = kw.pop(self.cls)

        # TODO: NamedElement requires 'name' to be a string, but in many cases
        #       this script treats 'name' as a dict.  Save the property off and
        #       insert it after ConfigEntry does its own thing to avoid
        #       exceptions.  This should be refactored throughout the whole
        #       script to not overload 'name' as a dict.
        name_save = kw.pop("name")
        super(ConfigEntry, self).__init__(**kw)
        self.name = name_save

    def factory(self, objs):
        """Optional factory interface for subclasses to add
        additional items to be rendered."""

        pass

    def setup(self, objs):
        """Optional setup interface for subclasses, invoked
        after all factory methods have been run."""

        pass


class Path(ConfigEntry):
    """Path/metadata association."""

    def __init__(self, *a, **kw):
        super(Path, self).__init__(**kw)

        if self.name["meta"].upper() != self.name["meta"]:
            raise InvalidConfigError(
                self.configfile,
                'Metadata tag "{0}" must be upper case.'.format(
                    self.name["meta"]
                ),
            )

    def factory(self, objs):
        """Create path and metadata elements."""

        args = {
            "class": "pathname",
            "pathname": "element",
            "name": self.name["path"],
        }
        add_unique(ConfigEntry(configfile=self.configfile, **args), objs)

        args = {"class": "meta", "meta": "element", "name": self.name["meta"]}
        add_unique(ConfigEntry(configfile=self.configfile, **args), objs)

        super(Path, self).factory(objs)

    def setup(self, objs):
        """Resolve path and metadata names to indices."""

        self.path = get_index(objs, "pathname", self.name["path"])
        self.meta = get_index(objs, "meta", self.name["meta"])

        super(Path, self).setup(objs)


class Property(ConfigEntry):
    """Property/interface/metadata association."""

    def __init__(self, *a, **kw):
        super(Property, self).__init__(**kw)

        if self.name["meta"].upper() != self.name["meta"]:
            raise InvalidConfigError(
                self.configfile,
                'Metadata tag "{0}" must be upper case.'.format(
                    self.name["meta"]
                ),
            )

    def factory(self, objs):
        """Create interface, property name and metadata elements."""

        args = {
            "class": "interface",
            "interface": "element",
            "name": self.name["interface"],
        }
        add_unique(ConfigEntry(configfile=self.configfile, **args), objs)

        args = {
            "class": "propertyname",
            "propertyname": "element",
            "name": self.name["property"],
        }
        add_unique(ConfigEntry(configfile=self.configfile, **args), objs)

        args = {"class": "meta", "meta": "element", "name": self.name["meta"]}
        add_unique(ConfigEntry(configfile=self.configfile, **args), objs)

        super(Property, self).factory(objs)

    def setup(self, objs):
        """Resolve interface, property and metadata to indices."""

        self.interface = get_index(objs, "interface", self.name["interface"])
        self.prop = get_index(objs, "propertyname", self.name["property"])
        self.meta = get_index(objs, "meta", self.name["meta"])

        super(Property, self).setup(objs)


class Instance(ConfigEntry):
    """Property/Path association."""

    def __init__(self, *a, **kw):
        super(Instance, self).__init__(**kw)

    def setup(self, objs):
        """Resolve elements to indices."""

        self.interface = get_index(
            objs, "interface", self.name["property"]["interface"]
        )
        self.prop = get_index(
            objs, "propertyname", self.name["property"]["property"]
        )
        self.propmeta = get_index(objs, "meta", self.name["property"]["meta"])
        self.path = get_index(objs, "pathname", self.name["path"]["path"])
        self.pathmeta = get_index(objs, "meta", self.name["path"]["meta"])

        super(Instance, self).setup(objs)


class PathInstance(ConfigEntry):
    """Path association."""

    def __init__(self, *a, **kw):
        super(PathInstance, self).__init__(**kw)

    def setup(self, objs):
        """Resolve elements to indices."""
        self.path = self.name["path"]["path"]
        self.pathmeta = self.name["path"]["meta"]
        super(PathInstance, self).setup(objs)


class Group(ConfigEntry):
    """Pop the members keyword for groups."""

    def __init__(self, *a, **kw):
        self.members = kw.pop("members")
        super(Group, self).__init__(**kw)


class ImplicitGroup(Group):
    """Provide a factory method for groups whose members are
    not explicitly declared in the config files."""

    def __init__(self, *a, **kw):
        super(ImplicitGroup, self).__init__(**kw)

    def factory(self, objs):
        """Create group members."""

        factory = Everything.classmap(self.subclass, "element")
        for m in self.members:
            args = {
                "class": self.subclass,
                self.subclass: "element",
                "name": m,
            }

            obj = factory(configfile=self.configfile, **args)
            add_unique(obj, objs)
            obj.factory(objs)

        super(ImplicitGroup, self).factory(objs)


class GroupOfPaths(ImplicitGroup):
    """Path group config file directive."""

    def __init__(self, *a, **kw):
        super(GroupOfPaths, self).__init__(**kw)

    def setup(self, objs):
        """Resolve group members."""

        def map_member(x):
            path = get_index(objs, "pathname", x["path"])
            meta = get_index(objs, "meta", x["meta"])
            return (path, meta)

        self.members = map(map_member, self.members)

        super(GroupOfPaths, self).setup(objs)


class GroupOfProperties(ImplicitGroup):
    """Property group config file directive."""

    def __init__(self, *a, **kw):
        self.type = kw.pop("type")
        self.datatype = sdbusplus.property.Property(
            name=kw.get("name"), type=self.type
        ).cppTypeName

        super(GroupOfProperties, self).__init__(**kw)

    def setup(self, objs):
        """Resolve group members."""

        def map_member(x):
            iface = get_index(objs, "interface", x["interface"])
            prop = get_index(objs, "propertyname", x["property"])
            meta = get_index(objs, "meta", x["meta"])

            return (iface, prop, meta)

        self.members = map(map_member, self.members)

        super(GroupOfProperties, self).setup(objs)


class GroupOfInstances(ImplicitGroup):
    """A group of property instances."""

    def __init__(self, *a, **kw):
        super(GroupOfInstances, self).__init__(**kw)

    def setup(self, objs):
        """Resolve group members."""

        def map_member(x):
            path = get_index(objs, "pathname", x["path"]["path"])
            pathmeta = get_index(objs, "meta", x["path"]["meta"])
            interface = get_index(
                objs, "interface", x["property"]["interface"]
            )
            prop = get_index(objs, "propertyname", x["property"]["property"])
            propmeta = get_index(objs, "meta", x["property"]["meta"])
            instance = get_index(objs, "instance", x)

            return (path, pathmeta, interface, prop, propmeta, instance)

        self.members = map(map_member, self.members)

        super(GroupOfInstances, self).setup(objs)


class GroupOfPathInstances(ImplicitGroup):
    """A group of path instances."""

    def __init__(self, *a, **kw):
        super(GroupOfPathInstances, self).__init__(**kw)

    def setup(self, objs):
        """Resolve group members."""

        def map_member(x):
            path = get_index(objs, "pathname", x["path"]["path"])
            pathmeta = get_index(objs, "meta", x["path"]["meta"])
            pathinstance = get_index(objs, "pathinstance", x)
            return (path, pathmeta, pathinstance)

        self.members = map(map_member, self.members)

        super(GroupOfPathInstances, self).setup(objs)


class HasPropertyIndex(ConfigEntry):
    """Handle config file directives that require an index to be
    constructed."""

    def __init__(self, *a, **kw):
        self.paths = kw.pop("paths")
        self.properties = kw.pop("properties")
        super(HasPropertyIndex, self).__init__(**kw)

    def factory(self, objs):
        """Create a group of instances for this index."""

        members = []
        path_group = get_index(
            objs, "pathgroup", self.paths, config=self.configfile
        )
        property_group = get_index(
            objs, "propertygroup", self.properties, config=self.configfile
        )

        for path in objs["pathgroup"][path_group].members:
            for prop in objs["propertygroup"][property_group].members:
                member = {
                    "path": path,
                    "property": prop,
                }
                members.append(member)

        args = {
            "members": members,
            "class": "instancegroup",
            "instancegroup": "instance",
            "name": "{0} {1}".format(self.paths, self.properties),
        }

        group = GroupOfInstances(configfile=self.configfile, **args)
        add_unique(group, objs, config=self.configfile)
        group.factory(objs)

        super(HasPropertyIndex, self).factory(objs)

    def setup(self, objs):
        """Resolve path, property, and instance groups."""

        self.instances = get_index(
            objs,
            "instancegroup",
            "{0} {1}".format(self.paths, self.properties),
            config=self.configfile,
        )
        self.paths = get_index(
            objs, "pathgroup", self.paths, config=self.configfile
        )
        self.properties = get_index(
            objs, "propertygroup", self.properties, config=self.configfile
        )
        self.datatype = objs["propertygroup"][self.properties].datatype
        self.type = objs["propertygroup"][self.properties].type

        super(HasPropertyIndex, self).setup(objs)


class HasPathIndex(ConfigEntry):
    """Handle config file directives that require an index to be
    constructed."""

    def __init__(self, *a, **kw):
        self.paths = kw.pop("paths")
        super(HasPathIndex, self).__init__(**kw)

    def factory(self, objs):
        """Create a group of instances for this index."""

        members = []
        path_group = get_index(
            objs, "pathgroup", self.paths, config=self.configfile
        )

        for path in objs["pathgroup"][path_group].members:
            member = {
                "path": path,
            }
            members.append(member)

        args = {
            "members": members,
            "class": "pathinstancegroup",
            "pathinstancegroup": "pathinstance",
            "name": "{0}".format(self.paths),
        }

        group = GroupOfPathInstances(configfile=self.configfile, **args)
        add_unique(group, objs, config=self.configfile)
        group.factory(objs)

        super(HasPathIndex, self).factory(objs)

    def setup(self, objs):
        """Resolve path and instance groups."""

        self.pathinstances = get_index(
            objs,
            "pathinstancegroup",
            "{0}".format(self.paths),
            config=self.configfile,
        )
        self.paths = get_index(
            objs, "pathgroup", self.paths, config=self.configfile
        )
        super(HasPathIndex, self).setup(objs)


class GroupOfFilters(ConfigEntry):
    """Handle config file directives that require an index for filters."""

    def __init__(self, *a, **kw):
        # Pop filters data for adding to the available filters array
        self.type = kw.pop("type")
        self.datatype = kw.pop("datatype", None)
        self.filters = kw.pop("filters", None)

        super(GroupOfFilters, self).__init__(**kw)

    def factory(self, objs):
        """Modify filters to add the property value type and
        make them of operation argument type."""
        if self.filters:
            # 'type' used within OpArgument to generate filter
            # argument values so add to each filter
            for f in self.filters:
                f["type"] = self.type
            self.filters = [OpArgument(**x) for x in self.filters]

        super(GroupOfFilters, self).factory(objs)


class PropertyWatch(HasPropertyIndex):
    """Handle the property watch config file directive."""

    def __init__(self, *a, **kw):
        # Pop optional filters for the properties being watched
        self.filters = kw.pop("filters", None)
        self.callback = kw.pop("callback", None)
        self.ignore_start_callback = kw.pop("ignore_start_callback", False)
        self.ignore_start_callback = (
            "true" if self.ignore_start_callback else "false"
        )
        super(PropertyWatch, self).__init__(**kw)

    def factory(self, objs):
        """Create any filters for this property watch."""

        if self.filters:
            # Get the datatype(i.e. "int64_t") of the properties in this watch
            # (Made available after all `super` classes init'd)
            datatype = objs["propertygroup"][
                get_index(
                    objs,
                    "propertygroup",
                    self.properties,
                    config=self.configfile,
                )
            ].datatype
            # Get the type(i.e. "int64") of the properties in this watch
            # (Made available after all `super` classes init'd)
            type = objs["propertygroup"][
                get_index(
                    objs,
                    "propertygroup",
                    self.properties,
                    config=self.configfile,
                )
            ].type
            # Construct the data needed to make the filters for
            # this watch available.
            # *Note: 'class', 'subclass', 'name' are required for
            # storing the filter data(i.e. 'type', 'datatype', & 'filters')
            args = {
                "type": type,
                "datatype": datatype,
                "filters": self.filters,
                "class": "filtersgroup",
                "filtersgroup": "filters",
                "name": self.name,
            }
            # Init GroupOfFilters class with this watch's filters' arguments
            group = GroupOfFilters(configfile=self.configfile, **args)
            # Store this group of filters so it can be indexed later
            add_unique(group, objs, config=self.configfile)
            group.factory(objs)

        super(PropertyWatch, self).factory(objs)

    def setup(self, objs):
        """Resolve optional filters and callback."""

        if self.filters:
            # Watch has filters, provide array index to access them
            self.filters = get_index(
                objs, "filtersgroup", self.name, config=self.configfile
            )

        if self.callback:
            self.callback = get_index(
                objs, "callback", self.callback, config=self.configfile
            )

        super(PropertyWatch, self).setup(objs)


class PathWatch(HasPathIndex):
    """Handle the path watch config file directive."""

    def __init__(self, *a, **kw):
        self.pathcallback = kw.pop("pathcallback", None)
        super(PathWatch, self).__init__(**kw)

    def setup(self, objs):
        """Resolve optional callback."""
        if self.pathcallback:
            self.pathcallback = get_index(
                objs, "pathcallback", self.pathcallback, config=self.configfile
            )
        super(PathWatch, self).setup(objs)


class Callback(HasPropertyIndex):
    """Interface and common logic for callbacks."""

    def __init__(self, *a, **kw):
        super(Callback, self).__init__(**kw)


class PathCallback(HasPathIndex):
    """Interface and common logic for callbacks."""

    def __init__(self, *a, **kw):
        super(PathCallback, self).__init__(**kw)


class ConditionCallback(ConfigEntry, Renderer):
    """Handle the journal callback config file directive."""

    def __init__(self, *a, **kw):
        self.condition = kw.pop("condition")
        self.instance = kw.pop("instance")
        self.defer = kw.pop("defer", None)
        super(ConditionCallback, self).__init__(**kw)

    def factory(self, objs):
        """Create a graph instance for this callback."""

        args = {
            "configfile": self.configfile,
            "members": [self.instance],
            "class": "callbackgroup",
            "callbackgroup": "callback",
            "name": [self.instance],
        }

        entry = CallbackGraphEntry(**args)
        add_unique(entry, objs, config=self.configfile)

        super(ConditionCallback, self).factory(objs)

    def setup(self, objs):
        """Resolve condition and graph entry."""

        self.graph = get_index(
            objs, "callbackgroup", [self.instance], config=self.configfile
        )

        self.condition = get_index(
            objs, "condition", self.name, config=self.configfile
        )

        super(ConditionCallback, self).setup(objs)

    def construct(self, loader, indent):
        return self.render(
            loader, "conditional.mako.cpp", c=self, indent=indent
        )


class Condition(HasPropertyIndex):
    """Interface and common logic for conditions."""

    def __init__(self, *a, **kw):
        self.callback = kw.pop("callback")
        self.defer = kw.pop("defer", None)
        super(Condition, self).__init__(**kw)

    def factory(self, objs):
        """Create a callback instance for this conditional."""

        args = {
            "configfile": self.configfile,
            "condition": self.name,
            "class": "callback",
            "callback": "conditional",
            "instance": self.callback,
            "name": self.name,
            "defer": self.defer,
        }

        callback = ConditionCallback(**args)
        add_unique(callback, objs, config=self.configfile)
        callback.factory(objs)

        super(Condition, self).factory(objs)


class CountCondition(Condition, Renderer):
    """Handle the count condition config file directive."""

    def __init__(self, *a, **kw):
        self.countop = kw.pop("countop")
        self.countbound = kw.pop("countbound")
        self.op = kw.pop("op")
        self.bound = kw.pop("bound")
        self.oneshot = TrivialArgument(
            type="boolean", value=kw.pop("oneshot", False)
        )
        super(CountCondition, self).__init__(**kw)

    def setup(self, objs):
        """Resolve type."""

        super(CountCondition, self).setup(objs)
        self.bound = TrivialArgument(type=self.type, value=self.bound)

    def construct(self, loader, indent):
        return self.render(loader, "count.mako.cpp", c=self, indent=indent)


class MedianCondition(Condition, Renderer):
    """Handle the median condition config file directive."""

    def __init__(self, *a, **kw):
        self.op = kw.pop("op")
        self.bound = kw.pop("bound")
        self.oneshot = TrivialArgument(
            type="boolean", value=kw.pop("oneshot", False)
        )
        super(MedianCondition, self).__init__(**kw)

    def setup(self, objs):
        """Resolve type."""

        super(MedianCondition, self).setup(objs)
        self.bound = TrivialArgument(type=self.type, value=self.bound)

    def construct(self, loader, indent):
        return self.render(loader, "median.mako.cpp", c=self, indent=indent)


class Journal(Callback, Renderer):
    """Handle the journal callback config file directive."""

    def __init__(self, *a, **kw):
        self.severity = kw.pop("severity")
        self.message = kw.pop("message")
        super(Journal, self).__init__(**kw)

    def construct(self, loader, indent):
        return self.render(loader, "journal.mako.cpp", c=self, indent=indent)


class Elog(Callback, Renderer):
    """Handle the elog callback config file directive."""

    def __init__(self, *a, **kw):
        self.error = kw.pop("error")
        self.metadata = [Metadata(**x) for x in kw.pop("metadata", {})]
        super(Elog, self).__init__(**kw)

    def construct(self, loader, indent):
        with open(args.gen_errors, "a") as fd:
            fd.write(self.render(loader, "errors.mako.hpp", c=self))
        return self.render(loader, "elog.mako.cpp", c=self, indent=indent)


class Event(Callback, Renderer):
    """Handle the event callback config file directive."""

    def __init__(self, *a, **kw):
        self.eventName = kw.pop("eventName")
        self.eventMessage = kw.pop("eventMessage")
        super(Event, self).__init__(**kw)

    def construct(self, loader, indent):
        return self.render(loader, "event.mako.cpp", c=self, indent=indent)


class EventPath(PathCallback, Renderer):
    """Handle the event path callback config file directive."""

    def __init__(self, *a, **kw):
        self.eventType = kw.pop("eventType")
        super(EventPath, self).__init__(**kw)

    def construct(self, loader, indent):
        return self.render(loader, "eventpath.mako.cpp", c=self, indent=indent)


class ElogWithMetadata(Callback, Renderer):
    """Handle the elog_with_metadata callback config file directive."""

    def __init__(self, *a, **kw):
        self.error = kw.pop("error")
        self.metadata = kw.pop("metadata")
        super(ElogWithMetadata, self).__init__(**kw)

    def construct(self, loader, indent):
        with open(args.gen_errors, "a") as fd:
            fd.write(self.render(loader, "errors.mako.hpp", c=self))
        return self.render(
            loader, "elog_with_metadata.mako.cpp", c=self, indent=indent
        )


class ResolveCallout(Callback, Renderer):
    """Handle the 'resolve callout' callback config file directive."""

    def __init__(self, *a, **kw):
        self.callout = kw.pop("callout")
        super(ResolveCallout, self).__init__(**kw)

    def construct(self, loader, indent):
        return self.render(
            loader, "resolve_errors.mako.cpp", c=self, indent=indent
        )


class Method(ConfigEntry, Renderer):
    """Handle the method callback config file directive."""

    def __init__(self, *a, **kw):
        self.service = kw.pop("service")
        self.path = kw.pop("path")
        self.interface = kw.pop("interface")
        self.method = kw.pop("method")
        self.args = [TrivialArgument(**x) for x in kw.pop("args", {})]
        super(Method, self).__init__(**kw)

    def factory(self, objs):
        args = {
            "class": "interface",
            "interface": "element",
            "name": self.service,
        }
        add_unique(ConfigEntry(configfile=self.configfile, **args), objs)

        args = {"class": "pathname", "pathname": "element", "name": self.path}
        add_unique(ConfigEntry(configfile=self.configfile, **args), objs)

        args = {
            "class": "interface",
            "interface": "element",
            "name": self.interface,
        }
        add_unique(ConfigEntry(configfile=self.configfile, **args), objs)

        args = {
            "class": "propertyname",
            "propertyname": "element",
            "name": self.method,
        }
        add_unique(ConfigEntry(configfile=self.configfile, **args), objs)

        super(Method, self).factory(objs)

    def setup(self, objs):
        """Resolve elements."""

        self.service = get_index(objs, "interface", self.service)

        self.path = get_index(objs, "pathname", self.path)

        self.interface = get_index(objs, "interface", self.interface)

        self.method = get_index(objs, "propertyname", self.method)

        super(Method, self).setup(objs)

    def construct(self, loader, indent):
        return self.render(loader, "method.mako.cpp", c=self, indent=indent)


class CallbackGraphEntry(Group):
    """An entry in a traversal list for groups of callbacks."""

    def __init__(self, *a, **kw):
        super(CallbackGraphEntry, self).__init__(**kw)

    def setup(self, objs):
        """Resolve group members."""

        def map_member(x):
            return get_index(objs, "callback", x, config=self.configfile)

        self.members = map(map_member, self.members)

        super(CallbackGraphEntry, self).setup(objs)


class PathCallbackGraphEntry(Group):
    """An entry in a traversal list for groups of callbacks."""

    def __init__(self, *a, **kw):
        super(PathCallbackGraphEntry, self).__init__(**kw)

    def setup(self, objs):
        """Resolve group members."""

        def map_member(x):
            return get_index(objs, "pathcallback", x, config=self.configfile)

        self.members = map(map_member, self.members)

        super(PathCallbackGraphEntry, self).setup(objs)


class GroupOfCallbacks(ConfigEntry, Renderer):
    """Handle the callback group config file directive."""

    def __init__(self, *a, **kw):
        self.members = kw.pop("members")
        super(GroupOfCallbacks, self).__init__(**kw)

    def factory(self, objs):
        """Create a graph instance for this group of callbacks."""

        args = {
            "configfile": self.configfile,
            "members": self.members,
            "class": "callbackgroup",
            "callbackgroup": "callback",
            "name": self.members,
        }

        entry = CallbackGraphEntry(**args)
        add_unique(entry, objs, config=self.configfile)

        super(GroupOfCallbacks, self).factory(objs)

    def setup(self, objs):
        """Resolve graph entry."""

        self.graph = get_index(
            objs, "callbackgroup", self.members, config=self.configfile
        )

        super(GroupOfCallbacks, self).setup(objs)

    def construct(self, loader, indent):
        return self.render(
            loader, "callbackgroup.mako.cpp", c=self, indent=indent
        )


class GroupOfPathCallbacks(ConfigEntry, Renderer):
    """Handle the callback group config file directive."""

    def __init__(self, *a, **kw):
        self.members = kw.pop("members")
        super(GroupOfPathCallbacks, self).__init__(**kw)

    def factory(self, objs):
        """Create a graph instance for this group of callbacks."""

        args = {
            "configfile": self.configfile,
            "members": self.members,
            "class": "pathcallbackgroup",
            "pathcallbackgroup": "pathcallback",
            "name": self.members,
        }

        entry = PathCallbackGraphEntry(**args)
        add_unique(entry, objs, config=self.configfile)
        super(GroupOfPathCallbacks, self).factory(objs)

    def setup(self, objs):
        """Resolve graph entry."""

        self.graph = get_index(
            objs, "callbackpathgroup", self.members, config=self.configfile
        )

        super(GroupOfPathCallbacks, self).setup(objs)

    def construct(self, loader, indent):
        return self.render(
            loader, "callbackpathgroup.mako.cpp", c=self, indent=indent
        )


class Everything(Renderer):
    """Parse/render entry point."""

    @staticmethod
    def classmap(cls, sub=None):
        """Map render item class and subclass entries to the appropriate
        handler methods."""
        class_map = {
            "path": {
                "element": Path,
            },
            "pathgroup": {
                "path": GroupOfPaths,
            },
            "propertygroup": {
                "property": GroupOfProperties,
            },
            "property": {
                "element": Property,
            },
            "watch": {
                "property": PropertyWatch,
            },
            "pathwatch": {
                "path": PathWatch,
            },
            "instance": {
                "element": Instance,
            },
            "pathinstance": {
                "element": PathInstance,
            },
            "callback": {
                "journal": Journal,
                "elog": Elog,
                "elog_with_metadata": ElogWithMetadata,
                "event": Event,
                "group": GroupOfCallbacks,
                "method": Method,
                "resolve callout": ResolveCallout,
            },
            "pathcallback": {
                "eventpath": EventPath,
                "grouppath": GroupOfPathCallbacks,
            },
            "condition": {
                "count": CountCondition,
                "median": MedianCondition,
            },
        }

        if cls not in class_map:
            raise NotImplementedError('Unknown class: "{0}"'.format(cls))
        if sub not in class_map[cls]:
            raise NotImplementedError(
                'Unknown {0} type: "{1}"'.format(cls, sub)
            )

        return class_map[cls][sub]

    @staticmethod
    def load_one_yaml(path, fd, objs):
        """Parse a single YAML file.  Parsing occurs in three phases.
        In the first phase a factory method associated with each
        configuration file directive is invoked.  These factory
        methods generate more factory methods.  In the second
        phase the factory methods created in the first phase
        are invoked.  In the last phase a callback is invoked on
        each object created in phase two.  Typically the callback
        resolves references to other configuration file directives."""

        factory_objs = {}
        for x in yaml.safe_load(fd.read()) or {}:
            # Create factory object for this config file directive.
            cls = x["class"]
            sub = x.get(cls)
            if cls == "group":
                cls = "{0}group".format(sub)

            factory = Everything.classmap(cls, sub)
            obj = factory(configfile=path, **x)

            # For a given class of directive, validate the file
            # doesn't have any duplicate names (duplicates are
            # ok across config files).
            if exists(factory_objs, obj.cls, obj.name, config=path):
                raise NotUniqueError(path, cls, obj.name)

            factory_objs.setdefault(cls, []).append(obj)
            objs.setdefault(cls, []).append(obj)

        for cls, items in factory_objs.items():
            for obj in items:
                # Add objects for template consumption.
                obj.factory(objs)

    @staticmethod
    def load(args):
        """Aggregate all the YAML in the input directory
        into a single aggregate."""

        objs = {}
        yaml_files = filter(
            lambda x: x.endswith(".yaml"), os.listdir(args.inputdir)
        )

        for x in sorted(yaml_files):
            path = os.path.join(args.inputdir, x)
            with open(path, "r") as fd:
                Everything.load_one_yaml(path, fd, objs)

        # Configuration file directives reference each other via
        # the name attribute; however, when rendered the reference
        # is just an array index.
        #
        # At this point all objects have been created but references
        # have not been resolved to array indices.  Instruct objects
        # to do that now.
        for cls, items in objs.items():
            for obj in items:
                obj.setup(objs)

        return Everything(**objs)

    def __init__(self, *a, **kw):
        self.pathmeta = kw.pop("path", [])
        self.paths = kw.pop("pathname", [])
        self.meta = kw.pop("meta", [])
        self.pathgroups = kw.pop("pathgroup", [])
        self.interfaces = kw.pop("interface", [])
        self.properties = kw.pop("property", [])
        self.propertynames = kw.pop("propertyname", [])
        self.propertygroups = kw.pop("propertygroup", [])
        self.instances = kw.pop("instance", [])
        self.pathinstances = kw.pop("pathinstance", [])
        self.instancegroups = kw.pop("instancegroup", [])
        self.pathinstancegroups = kw.pop("pathinstancegroup", [])
        self.watches = kw.pop("watch", [])
        self.pathwatches = kw.pop("pathwatch", [])
        self.callbacks = kw.pop("callback", [])
        self.pathcallbacks = kw.pop("pathcallback", [])
        self.callbackgroups = kw.pop("callbackgroup", [])
        self.pathcallbackgroups = kw.pop("pathcallbackgroup", [])
        self.conditions = kw.pop("condition", [])
        self.filters = kw.pop("filtersgroup", [])

        super(Everything, self).__init__(**kw)

    def generate_cpp(self, loader):
        """Render the template with the provided data."""
        # errors.hpp is used by generated.hpp to included any error.hpp files
        open(args.gen_errors, "w+")

        with open(args.output, "w") as fd:
            fd.write(
                self.render(
                    loader,
                    args.template,
                    meta=self.meta,
                    properties=self.properties,
                    propertynames=self.propertynames,
                    interfaces=self.interfaces,
                    paths=self.paths,
                    pathmeta=self.pathmeta,
                    pathgroups=self.pathgroups,
                    propertygroups=self.propertygroups,
                    instances=self.instances,
                    pathinstances=self.pathinstances,
                    watches=self.watches,
                    pathwatches=self.pathwatches,
                    instancegroups=self.instancegroups,
                    pathinstancegroups=self.pathinstancegroups,
                    callbacks=self.callbacks,
                    pathcallbacks=self.pathcallbacks,
                    callbackgroups=self.callbackgroups,
                    pathcallbackgroups=self.pathcallbackgroups,
                    conditions=self.conditions,
                    filters=self.filters,
                    indent=Indent(),
                )
            )


if __name__ == "__main__":
    script_dir = os.path.dirname(os.path.realpath(__file__))
    valid_commands = {
        "generate-cpp": "generate_cpp",
    }

    parser = ArgumentParser(
        description=(
            "Phosphor DBus Monitor (PDM) YAML scanner and code generator."
        )
    )

    parser.add_argument(
        "-o",
        "--out",
        dest="output",
        default="generated.cpp",
        help="Generated output file name and path.",
    )
    parser.add_argument(
        "-t",
        "--template",
        dest="template",
        default="generated.mako.hpp",
        help="The top level template to render.",
    )
    parser.add_argument(
        "-e",
        "--errors",
        dest="gen_errors",
        default="errors.hpp",
        help="Generated errors.hpp output filename.",
    )
    parser.add_argument(
        "-p",
        "--template-path",
        dest="template_search",
        default=script_dir,
        help="The space delimited mako template search path.",
    )
    parser.add_argument(
        "-d",
        "--dir",
        dest="inputdir",
        default=os.path.join(script_dir, "example"),
        help="Location of files to process.",
    )
    parser.add_argument(
        "command",
        metavar="COMMAND",
        type=str,
        choices=valid_commands.keys(),
        help="%s." % " | ".join(valid_commands.keys()),
    )

    args = parser.parse_args()

    if sys.version_info < (3, 0):
        lookup = mako.lookup.TemplateLookup(
            directories=args.template_search.split(), disable_unicode=True
        )
    else:
        lookup = mako.lookup.TemplateLookup(
            directories=args.template_search.split()
        )
    try:
        function = getattr(Everything.load(args), valid_commands[args.command])
        function(lookup)
    except InvalidConfigError as e:
        sys.stdout.write("{0}: {1}\n\n".format(e.config, e.msg))
        raise
