{%- for import in imports %}
/// <reference path="./{{ import.name }}-{{ import.version }}.d.ts" />
{%- endfor %}

/**
 * Type Definitions for GJS (https://gjs.guide/), generated by [GirGen](https://github.com/aylur/girgen)
 * If you found a bug, create a bug report on [GirGen's Repository](https://github.com/aylur/girgen/issues/new)
 */
{% for namespace in namespaces -%}
declare module "gi://{{ namespace.name }}?version={{ namespace.version }}" {
    {%- for import in imports %}
    import type {{ import.name }} from "gi://{{ import.name }}?version={{ import.version }}"
    {%- endfor %}

    /**
     * Do **not** import this at runtime.
     * This namespace is only exported for module augmentation.
     */
    export namespace GI {
        {{ namespace.extra_content|indent(8) }}

        namespace {{ namespace.name }} {
            {%- for class in namespace.classes %}
            {{ class|indent(12) }}
            {%- endfor %}

            {%- for interface in namespace.interfaces %}
            {{ interface|indent(12) }}
            {%- endfor %}

            {%- for record in namespace.records %}
            {{ record|indent(12) }}
            {%- endfor %}

            {%- for union in namespace.unions %}
            {{ union|indent(12) }}
            {%- endfor %}

            {%- for enum in namespace.enums %}
            {{ enum|indent(12) }}
            {%- endfor %}

            {%- for bitfield in namespace.bitfields %}
            {{ bitfield|indent(12) }}
            {%- endfor %}

            {%- for callback in namespace.callbacks %}
            {{ callback|indent(12) }}
            {%- endfor %}

            {%- for alias in namespace.aliases %}
            {{ alias|indent(12) }}
            {%- endfor %}

            interface $Exports {
                __name__: "{{ namespace.name }}"
                __version__: "{{ namespace.version }}"

                {%- for constant in namespace.constants %}
                {{ constant|indent(16) }}
                {%- endfor %}

                {%- for function in namespace.functions %}
                {{ function|indent(16) }}
                {%- endfor %}
            }
        }

        const {{ namespace.name }}: {{ namespace.name }}.$Exports
    }

    export default GI.{{ namespace.name }}
}
{%- endfor -%}
