/// <reference path="api.d.ts" />

/* tslint:disable:no-unused-variable member-ordering */

{{#operations}}
module {{package}} {
    'use strict';

{{#description}}
    /**
    * {{&description}}
    */
{{/description}}
    export class {{classname}} {
        private basePath = '{{contextPath}}';

        static $inject: string[] = ['$http'];

        constructor(private $http: ng.IHttpService, basePath?: string) {
            if (basePath) {
                this.basePath = basePath;
            }
        }
{{#operation}}

        public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any ) : ng.IHttpPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> {
            var path = this.basePath + '{{path}}';

{{#pathParams}}
            path = path.replace('{' + '{{paramName}}' + '}', String({{paramName}}));

{{/pathParams}}
            var queryParameters: any = {};
            var headerParams: any = {};

{{#allParams}}
{{#required}}
            // verify required parameter '{{paramName}}' is set
            if (!{{paramName}}) {
                throw new Error('Missing required parameter {{paramName}} when calling {{nickname}}');
            }

{{/required}}
{{/allParams}}
{{#queryParams}}
            if ({{paramName}} !== undefined) {
                queryParameters['{{paramName}}'] = {{paramName}};
            }

{{/queryParams}}
{{#headerParams}}
            headerParams['{{paramName}}'] = {{paramName}};

{{/headerParams}}
            var httpRequestParams: any = {
                method: '{{httpMethod}}',
                url: path,
                json: true,
                {{#bodyParam}}data: {{paramName}},
                {{/bodyParam}}
                params: queryParameters,
                headers: headerParams
            };

            if (extraHttpRequestParams) {
                for (var k in extraHttpRequestParams) {
                    if (extraHttpRequestParams.hasOwnProperty(k)) {
                        httpRequestParams[k] = extraHttpRequestParams[k];
                    }
                }
            }

            return this.$http(httpRequestParams);
        }
{{/operation}}
    }
}
{{/operations}}
