{%- set typename = name|escape_toplevel %}

interface {{ name }}Struct {
    readonly $gtype: GObject.GType<{{ typename }}>

    {%- if constructor %}
    {{ constructor|indent(4) }}
    {%- elif bag_constructor %}
    new (fields?: {
        {%- for field in fields %}
        {{ field.name }}?: {{ field.type }}
        {%- endfor %}
    }): {{ typename }}
    {%- else %}
    [Symbol.hasInstance](instance: unknown): instance is {{ typename }}
    {%- endif %}

    {%- for ctor in constructors %}
    {{ ctor|indent(4) }}
    {%- endfor %}

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

interface {{ typename }} {
    {%- for field in fields %}
    {{ field.jsdoc|indent(4) }}
    {{ field.name }}: {{ field.type }}
    {%- endfor %}

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

interface $Exports {
    {{ name|escape_member }}: {{ name }}Struct
}
