/**
 * Do not modify this file, it is auto-generated.
 */
{{#each otherImports}}
import { {{#each this}}{{{this}}}{{#unless @last}}, {{/unless}}{{/each}} } from '{{{@key}}}';
{{/each}}

export const TYPE_ID = '{{{jsEscape id}}}';
export const TYPE_NAME = '{{{jsEscape name}}}';
{{#each bindings}}
export const {{{ this.constant }}} = '{{{jsEscape this.key}}}';
{{/each}}

/*
{{#if name}}
 * @name {{{name}}}
{{/if}}
{{#if id}}
 * @id {{{id}}}
{{/if}}
{{#if description}}
 * @description {{{description}}}
{{/if}}
{{#if creator}}
 * @author {{{creator}}}
{{/if}}
 */
export interface {{{definitionName}}} {
{{#each bindings}}

    /**
{{{this.comment}}}
    */
    ['{{{jsEscape this.key}}}']{{#if this.optional}}?{{/if}}: {{{this.type}}};
{{/each}}
}

export interface {{{baseElementClass}}} extends GroupElement {
    /**
    * Pin the type reference to the well known ID
    */
    typeRef: {
        id: '{{{jsEscape this.id}}}'
    };
}

export interface {{{singleElementClass}}} extends {{{baseElementClass}}} {
    value: {{{definitionName}}};
}

export interface {{{multiElementClass}}} extends {{{baseElementClass}}} {
    values: {{{definitionName}}}[];
}

/**
 * Tests if the value is of type {{{baseElementClass}}}
 *
 * @param aValue the value to test
 * @return true if the value if of type {{{baseElementClass}}} else false
*/
export function is{{{definitionName}}}(aValue: any): aValue is {{{definitionName}}} {
{{#if hasBindings}}
    return !!aValue
{{#each bindings}}
{{#if this.validator}}
{{#if this.required}}
        && {{{ this.validator }}}(aValue[{{{jsEscape this.constant}}}], false)
{{else}}
        && (!aValue[{{{jsEscape this.constant}}}] || {{{ this.validator }}}(aValue[{{{jsEscape this.this.constant}}}], true))
{{/if}}
{{/if}}
{{/each}}
        ;
{{else}}
    return !!aValue;
{{/if}}
}

/**
 * Tests if the value is of type {{{singleElementClass}}}
 *
 * @param aValue the value to test
 * @return true if the value if of type {{{singleElementClass}}} else false
*/
export function is{{{singleElementClass}}}(aValue: any): aValue is {{{singleElementClass}}} {
    return isSingleGroupElement(aValue) && is{{{definitionName}}}(aValue.value);
}

/**
 * Tests if the value is of type {{{multiElementClass}}}
 *
 * @param aValue the value to test
 * @return true if the value if of type {{{multiElementClass}}} else false
*/
export function is{{{multiElementClass}}}(aValue: any): aValue is {{{multiElementClass}}} {
    return isMultiGroupElement(aValue) && aValue.values.every(is{{{definitionName}}});
}

/*
{{#if name}}
 * @name {{{name}}}
{{/if}}
{{#if id}}
 * @id {{{id}}}
{{/if}}
{{#if description}}
 * @description {{{description}}}
{{/if}}
{{#if creator}}
 * @author {{{creator}}}
{{/if}}
 */
export interface {{{simpleTypeName}}} {
{{#each bindings}}

    /**
{{{this.comment}}}
    */
    ['{{{jsEscape this.key}}}']{{#if this.optional}}?{{/if}}: {{{this.simpleTypeName}}};
{{/each}}
}
