#
# Generated by "infrahubctl protocols"
#

from __future__ import annotations

from typing import TYPE_CHECKING, Optional

from infrahub_sdk.protocols import {{ "CoreNode" | syncify(sync) }}, {{ base_protocols | join(', ') }}

if TYPE_CHECKING:
    from infrahub_sdk.node import {{ "RelatedNode" | syncify(sync) }}, {{ "RelationshipManager" | syncify(sync) }}
    from infrahub_sdk.protocols_base import (
        AnyAttribute,
        AnyAttributeOptional,
        String,
        StringOptional,
        Integer,
        IntegerOptional,
        Boolean,
        BooleanOptional,
        DateTime,
        DateTimeOptional,
        Dropdown,
        DropdownOptional,
        HashedPassword,
        HashedPasswordOptional,
        MacAddress,
        MacAddressOptional,
        IPHost,
        IPHostOptional,
        IPNetwork,
        IPNetworkOptional,
        JSONAttribute,
        JSONAttributeOptional,
        ListAttribute,
        ListAttributeOptional,
        URL,
        URLOptional,
    )

{% for generic in generics %}

class {{ generic.namespace + generic.name }}({{core_node_name}}):
    {% if not generic.attributes|default([]) and not generic.relationships|default([]) %}
    pass
    {% endif %}
    {% for attribute in generic.attributes | sort(attribute='name') | default([]) %}
    {{ attribute | render_attribute }}
    {% endfor %}
    {% for relationship in generic.relationships | sort(attribute='name') | default([]) %}
    {{ relationship | render_relationship(sync) }}
    {% endfor %}
    {% if generic.hierarchical | default(false) %}
    parent: {{ "RelatedNode" | syncify(sync) }}
    children: {{ "RelationshipManager" | syncify(sync) }}
    {% endif %}
{% endfor %}


{% for node in nodes %}

class {{ node.namespace + node.name }}({{ node.inherit_from | syncify(sync) | join(", ") or core_node_name }}):
    {% if not node.attributes|default([]) and not node.relationships|default([]) %}
    pass
    {% endif %}
    {% for attribute in node.attributes | sort(attribute='name') | default([]) %}
    {{ attribute | render_attribute }}
    {% endfor %}
    {% for relationship in node.relationships | sort(attribute='name') | default([]) %}
    {{ relationship | render_relationship(sync) }}
    {% endfor %}
    {% if node.hierarchical | default(false) %}
    parent: {{ "RelatedNode" | syncify(sync) }}
    children: {{ "RelationshipManager" | syncify(sync) }}
    {% endif %}

{% endfor %}


{% for node in profiles %}

class {{ node.namespace + node.name }}({{ node.inherit_from | syncify(sync) | join(", ") or core_node_name }}):
    {% if not node.attributes|default([]) and not node.relationships|default([]) %}
    pass
    {% endif %}
    {% for attribute in node.attributes | sort(attribute='name') | default([]) %}
    {{ attribute | render_attribute }}
    {% endfor %}
    {% for relationship in node.relationships | sort(attribute='name') | default([]) %}
    {{ relationship | render_relationship(sync) }}
    {% endfor %}
    {% if node.hierarchical | default(false) %}
    parent: {{ "RelatedNode" | syncify(sync) }}
    children: {{ "RelationshipManager" | syncify(sync) }}
    {% endif %}

{% endfor %}


{% for node in templates %}

class {{ node.namespace + node.name }}({{ node.inherit_from | syncify(sync) | join(", ") or core_node_name }}):
    {% if not node.attributes|default([]) and not node.relationships|default([]) %}
    pass
    {% endif %}
    {% for attribute in node.attributes | sort(attribute='name') | default([]) %}
    {{ attribute | render_attribute }}
    {% endfor %}
    {% for relationship in node.relationships | sort(attribute='name') | default([]) %}
    {{ relationship | render_relationship(sync) }}
    {% endfor %}

{% endfor %}