/**
 * This file is generated by the SwaggerTSGenerator.
 * Do not edit.
*/
/* tslint:disable */
{{#if generateClasses}}
import { Validators, FormControl, FormGroup, FormArray, ValidatorFn } from '@angular/forms';
import { minValueValidator, maxValueValidator, enumValidator } from '{{type.pathToRoot}}validators';
import { BaseModel } from '{{type.pathToRoot}}base-model';
{{/if}}

{{#with type}}
    {{#if isSubType}}
import { {{baseType.typeName}} } from '{{baseImportFile}}';
    {{/if}}
{{#properties}}
    {{#if isUniqueImportType}}
import { {{importType}} } from '{{importFile}}';
    {{/if}}
    {{#if isUniqueImportEnumType}}
import { {{importEnumType}} } from '{{../../enumRef}}';
    {{/if}}
{{/properties}}

{{#if ../generateClasses}}
export interface I{{{typeName}}} {
{{else}}
export interface {{{typeName}}} {
{{/if}}
{{#properties}}
    {{name}}{{#unless validators.validation.required}}?{{/unless}}: {{{typeName}}};
{{/properties}}
}

{{#if ../generateClasses}}

export class {{{typeName}}}{{#if isSubType}} extends {{{baseType.typeName}}}{{/if}} extends BaseModel implements I{{{typeName}}} {
{{#properties}}
    {{#if description}}
    /** {{{description}}} */
    {{/if}}
    {{name}}: {{{typeName}}};
{{/properties}}

    /**
     * constructor
     * @param values Can be used to set a webapi response to this newly constructed model
    */
    constructor(values?: any) {
        super();
{{#if isSubType}}

        this.$type = '{{{fullNamespace}}}.{{{typeName}}}';
{{/if}}
{{#properties}}
    {{#if isComplexType}}
        this.{{name}} = new {{{typeName}}}();
    {{/if}}
{{/properties}}
        if (values) {
            this.setValues(values);
        }
    }

    /**
     * set the values.
     * @param values Can be used to set a webapi response to this newly constructed model
    */
    setValues(values: any): void {
        if (values) {
{{#properties}}
    {{#if isArray}}
            this.fillModelArray<{{arrayTypeName}}>(this, '{{name}}', values.{{name}}{{#if isArrayComplexType}}, {{arrayTypeName}}{{/if}});
    {{else}}
        {{#if isComplexType}}
            this.{{name}}.setValues(values.{{name}});
        {{else}}
            this.{{name}} = values.{{name}};
        {{/if}}
    {{/if}}
{{/properties}}
        }
    }

    protected getFormGroup(): FormGroup {
        if (!this._formGroup) {
            this._formGroup = new FormGroup({
{{#properties}}
{{#if isArray}}
                {{name}}: new FormArray([]),
{{else if isImportType}}
                {{name}}: this.{{name}}.$formGroup,
{{else if hasValidation}}
                {{name}}: new FormControl(this.{{name}}, [{{#each validators.validatorArray}}{{{this}}}, {{/each}}]),
{{else}}
                {{name}}: new FormControl(this.{{name}}),
{{/if}}
{{/properties}}
            });
{{#properties}}
{{#if isArray}}
            // generate FormArray control elements
            this.fillFormArray<{{arrayTypeName}}>('{{name}}', this.{{name}}{{#if isArrayComplexType}}, {{arrayTypeName}}{{/if}});
{{/if}}
{{/properties}}
        }
        return this._formGroup;
    }

    setFormGroupValues() {
        if (this._formGroup) {
{{#properties}}
{{#if isArray}}
            this.fillModelArray<{{arrayTypeName}}>(this, '{{name}}', this.{{name}}{{#if isArrayComplexType}}, {{arrayTypeName}}{{/if}});
{{else if isImportType}}
            this.{{name}}.setFormGroupValues();
{{else}}
            this._formGroup.controls['{{name}}'].setValue(this.{{name}});
{{/if}}
{{/properties}}
        }
    }
}

{{/if}}
{{/with}}
