{%- from "introspection" import extend_list %}
{%- set typename = name|escape_toplevel %}
{%- set typename_class = name_class|escape_toplevel %}

namespace {{ typename }} {
    {% include "introspection" %}

    interface Interface {{ extend_list(extends) }} {
        {%- for method in virtual_methods %}
        {{ method|indent(8) }}
        {%- endfor %}
    }
}

interface {{ typename }} {{ extend_list(extends+[typename+".Interface"]) }} {
    readonly $signals: {{ typename }}.SignalSignatures
    readonly $readableProperties: {{ typename }}.ReadableProperties
    readonly $writableProperties: {{ typename }}.WritableProperties
    readonly $constructOnlyProperties: {{ typename }}.ConstructOnlyProperties

    {%- for property in properties %}
    {{ property.jsdoc|indent(4) }}
    {%- if property.readable %}
    get {{ property.name|camel_case }}(): {{ property.type }}
    {%- endif %}
    {%- if property.writable and not property.constuct_only %}
    set {{ property.name|camel_case }}(value: {{ property.type }})
    {%- endif %}
    {%- endfor %}

    {%- for method in methods %}
    {{ method|indent(4) }}
    {%- endfor %}
}

interface {{ typename_class }} {
    readonly $gtype: GObject.GType<{{ typename }}>
    readonly prototype: {{ typename }}
    [Symbol.hasInstance](instance: unknown): instance is {{ typename }}

    {%- for fn in functions %}
    {{ fn|indent(4) }}
    {%- endfor %}

    {%- for fn in class_functions %}
    {{ fn|indent(4) }}
    {%- endfor %}
}

interface $Exports {
    {{ jsdoc|indent(4) if jsdoc }}
    {{ name|escape_member }}: {{ typename_class }}
}
