// This file was generated with XrmTypesGen
// GitHub: https://github.com/OliverFlint/XrmTypesGen

declare namespace Xrm {
    namespace Ext.Forms.{{toTypeName data.objecttypecode}}.{{formtype data.type}}.{{toTypeName data.name}} {
        /**
        * Entity/Table Name: `{{data.objecttypecode}}`
        *
        * Form Type: `{{formtype data.type}}`
        *
        * Form Name: `{{toTypeName data.name}}`
        */
        interface Form extends Extensions.FormContext {};
        namespace Extensions {
            type FormContext = Xrm.FormContext & {
                //#region form context attributes
                {{#each formObj.Tabs.$values}}
                    {{#each this.Columns.$values}}
                        {{#each this.Sections.$values}}
                            {{#each this.Rows.$values}}
                                {{#each this.Cells.$values}}
                                    {{#if (getFieldName this.Control)}}
                                        {{#if (getAttributeType ../../../../../meta (getFieldName this.Control) this.Control.ClassId 'attribute')}}
                                        /**
                                        * Gets the `{{getFieldName this.Control}}` attribute.
                                        *
                                        * @returns `{{getAttributeType ../../../../../meta (getFieldName this.Control) this.Control.ClassId 'attribute'}}`.
                                        */
                                        getAttribute(attributeName: "{{getFieldName this.Control}}"): {{getAttributeType ../../../../../meta (getFieldName this.Control) this.Control.ClassId 'attribute'}}
                                        {{/if}}
                                    {{/if}}
                                {{/each}}
                            {{/each}}
                        {{/each}}
                    {{/each}}
                {{/each}}
                //#endregion
                //#region form context contols
                {{#each formObj.Tabs.$values}}
                    {{#each this.Columns.$values}}
                        {{#each this.Sections.$values}}
                            {{#each this.Rows.$values}}
                                {{#each this.Cells.$values}}
                                    {{#if (getFieldName this.Control)}}
                                        {{#if (getAttributeType ../../../../../meta (getFieldName this.Control) this.Control.ClassId 'control')}}
                                        /**
                                        * Gets the `{{getFieldName this.Control}}` control.
                                        *
                                        * @returns `{{getAttributeType ../../../../../meta (getFieldName this.Control) this.Control.ClassId 'control'}}`.
                                        */
                                        getControl(controlName: "{{getFieldName this.Control}}"): {{getAttributeType ../../../../../meta (getFieldName this.Control) this.Control.ClassId 'control'}}
                                        {{/if}}
                                    {{/if}}
                                {{/each}}
                            {{/each}}
                        {{/each}}
                    {{/each}}
                {{/each}}
                //#endregion    

                data: Data
                ui: Ui
            }
            
            type Controls = Xrm.Collection.ItemCollection<Xrm.Controls.Control> & {
                {{#each formObj.Tabs.$values}}
                    {{#each this.Columns.$values}}
                        {{#each this.Sections.$values}}
                            {{#each this.Rows.$values}}
                                {{#each this.Cells.$values}}
                                    {{#if (getFieldName this.Control)}}
                                        {{#if (getAttributeType ../../../../../meta (getFieldName this.Control) this.Control.ClassId 'control')}}
                                        /**
                                        * Gets the `{{getFieldName this.Control}}` control.
                                        *
                                        * @returns `{{getAttributeType ../../../../../meta (getFieldName this.Control) this.Control.ClassId 'control'}}`.
                                        */
                                        get(controlName: "{{getFieldName this.Control}}"): {{getAttributeType ../../../../../meta (getFieldName this.Control) this.Control.ClassId 'control'}}
                                        {{/if}}
                                    {{/if}}
                                {{/each}}
                            {{/each}}
                        {{/each}}
                    {{/each}}
                {{/each}}
            }
            
            type Attributes = Xrm.Collection.ItemCollection<Xrm.Attributes.Attribute> & {
                {{#each formObj.Tabs.$values}}
                    {{#each this.Columns.$values}}
                        {{#each this.Sections.$values}}
                            {{#each this.Rows.$values}}
                                {{#each this.Cells.$values}}
                                    {{#if (getFieldName this.Control)}}
                                        {{#if (getAttributeType ../../../../../meta (getFieldName this.Control) this.Control.ClassId 'attribute')}}
                                        /**
                                        * Gets the `{{getFieldName this.Control}}` attribute.
                                        *
                                        * @returns `{{getAttributeType ../../../../../meta (getFieldName this.Control) this.Control.ClassId 'attribute'}}`.
                                        */
                                        get(attributeName: "{{getFieldName this.Control}}"): {{getAttributeType ../../../../../meta (getFieldName this.Control) this.Control.ClassId 'attribute'}}
                                        {{/if}}
                                    {{/if}}
                                {{/each}}
                            {{/each}}
                        {{/each}}
                    {{/each}}
                {{/each}}
            }
            
            type Data = Xrm.Data & {
                attributes: Attributes
            }
            
            type Ui = Xrm.Ui & {
                tabs: Tabs
                controls: Controls
            }
            
            type Tabs = Xrm.Collection.ItemCollection<Xrm.Controls.Tab> & {
                {{#each formObj.Tabs.$values}}
                /**
                * Gets the `{{Name}}` tab.
                *
                * @returns `Xrm.Controls.Tab`.
                */
                get(tabname: "{{Name}}"): {{toTypeName Name}}TabControl
                {{/each}}
            }

            {{#each formObj.Tabs.$values}}
            type {{toTypeName Name}}TabControl = Xrm.Controls.Tab & {
                sections: {{toTypeName Name}}TabSections
            }
            {{/each}}

            {{#each formObj.Tabs.$values}}
            type {{toTypeName Name}}TabSections = Xrm.Collection.ItemCollection<Xrm.Controls.Section> & {
                {{#each this.Columns.$values}}
                    {{#each this.Sections.$values}}
                    /**
                    * Gets the `{{Name}}` section.
                    *
                    * @returns `Xrm.Controls.Section`.
                    */
                    get(sectionname: "{{Name}}"): {{toTypeName Name}}SectionControl
                    {{/each}}
                {{/each}}
            }
            {{/each}}

            {{#each formObj.Tabs.$values}}
                {{#each this.Columns.$values}}
                    {{#each this.Sections.$values}}
                    type {{toTypeName Name}}SectionControl = Xrm.Controls.Section & {
                        controls: {{toTypeName Name}}SectionControls
                    }
                    {{/each}}
                {{/each}}
            {{/each}}

            {{#each formObj.Tabs.$values}}
                {{#each this.Columns.$values}}
                    {{#each this.Sections.$values}}
                    type {{toTypeName Name}}SectionControls = Xrm.Collection.ItemCollection<Xrm.Controls.Control> & {
                        {{#each this.Rows.$values}}
                            {{#each this.Cells.$values}}
                                {{#if (getFieldName this.Control)}}
                                /**
                                * Gets the `{{getFieldName this.Control}}` control.
                                *
                                * @returns `{{getAttributeType ../../../../../meta (getFieldName this.Control) this.Control.ClassId 'control'}}`.
                                */
                                get(controlname: "{{getFieldName this.Control}}"): {{getAttributeType ../../../../../meta (getFieldName this.Control) this.Control.ClassId 'control'}}
                                {{/if}}
                            {{/each}}
                        {{/each}}
                    }
                    {{/each}}
                {{/each}}
            {{/each}}
        }
    }
}