{% if GeneratePartialControllers -%}
[System.CodeDom.Compiler.GeneratedCode("NSwag", "{{ ToolchainVersion }}")]
public interface I{{ Class }}Controller
{
{%-     for operation in Operations %}
{%-         if operation.HasSummary %}
    /// <summary>
    /// {{ operation.Summary | csharpdocs }}
    /// </summary>
{%-         endif %}
{%          if operation.HasDescription -%}
    /// <remarks>
    /// {{ operation.Description | csharpdocs }}
    /// </remarks>
{%          endif -%}
{%-         for parameter in operation.Parameters %}
{%-             if parameter.HasDescription %}
    /// <param name="{{ parameter.VariableName }}">{{ parameter.Description | csharpdocs }}</param>
{%-             endif %}
{%-         endfor %}
{%-         if operation.HasResultDescription %}
    /// <returns>{{ operation.ResultDescription | csharpdocs }}</returns>
{%         endif -%}
{%-         if operation.IsDeprecated %}
    [System.Obsolete]
{%-         endif %}
    {{ operation.ResultType }} {{ operation.ActualOperationName }}Async({% for parameter in operation.Parameters %}{% assign parameterOptional = GenerateOptionalParameters and parameter.IsOptional %}{{ parameter.TypeInControllerInterface }} {{ parameter.VariableName }}{% if parameterOptional and parameter.HasDefault == false %} = null{% endif %}{% if parameter.IsLast == false or UseCancellationToken %}, {% endif %}{% endfor %}{% if UseCancellationToken %}System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken){% endif %});

{%-      endfor %}
}
{%- endif %}

[System.CodeDom.Compiler.GeneratedCode("NSwag", "{{ ToolchainVersion }}")]
{%- if HasBasePath -%}
{%-     if IsAspNetCore -%}
[{{ AspNetNamespace }}.Route("{{ BasePath }}")]
{%-     else -%}
[{{ AspNetNamespace }}.RoutePrefix("{{ BasePath }}")]
{%-     endif -%}
{%- endif -%}
{%- if GeneratePartialControllers -%}
{% template Controller.Class.Annotations %}
public partial class {{ Class }}Controller : {% if HasBaseClass %}{{ BaseClass }}{% else %}{{ AspNetNamespace }}.{% if IsAspNetCore %}ControllerBase{% else %}ApiController{% endif %}{% endif %}
{
    private I{{ Class }}Controller _implementation;

    public {{ Class }}Controller(I{{ Class }}Controller implementation)
    {
        _implementation = implementation;
    }

{%     for operation in Operations -%}
{%         if operation.HasSummary -%}
    /// <summary>
    /// {{ operation.Summary | csharpdocs }}
    /// </summary>
{%         endif -%}
{%         if operation.HasDescription -%}
    /// <remarks>
    /// {{ operation.Description | csharpdocs }}
    /// </remarks>
{%         endif -%}
{%         for parameter in operation.Parameters -%}
{%             if parameter.HasDescription -%}
    /// <param name="{{ parameter.VariableName }}">{{ parameter.Description | csharpdocs }}</param>
{%             endif -%}
{%         endfor -%}
{%         if operation.HasResultDescription -%}
    /// <returns>{{ operation.ResultDescription | csharpdocs }}</returns>
{%         endif -%}
{%         if operation.IsDeprecated -%}
    [System.Obsolete]
{%         endif -%}
    {% template Controller.Method.Annotations %}
    [{{ AspNetNamespace }}.Http{{ operation.HttpMethodUpper }}, {{ AspNetNamespace }}.Route("{{ operation.Path }}"{% if operation.HasRouteName %}, Name = "{{ operation.RouteName }}"{% endif %})]
    public {% if IsAspNetCore and operation.WrapResponse %}async System.Threading.Tasks.Task<Microsoft.AspNetCore.Mvc.IActionResult>{% elsif operation.WrapResponse %}async System.Threading.Tasks.Task<HttpResponseMessage>{% else %}{{ operation.ResultType }}{% endif %} {{ operation.ActualOperationName }}({% for parameter in operation.Parameters %}{% if parameter.IsQuery %}[{{ AspNetNamespace }}.{% if IsAspNetCore -%}FromQuery{% else -%}FromUri{%- endif %}{% if parameter.IsValidIdentifier == false %}(Name = "{{ parameter.Name }}"){% endif %}] {% endif %}{% if parameter.IsHeader %}[{% if IsAspNetCore -%}{{ AspNetNamespace }}.{%- endif %}FromHeader{% if parameter.IsValidIdentifier == false %}(Name = "{{ parameter.Name }}"){% endif %}] {% endif %}{% if parameter.IsBody and parameter.IsBinaryBody == false %}[{{ AspNetNamespace }}.FromBody] {% endif %}{% if GenerateModelValidationAttributes and parameter.IsRequired %}[{{ RequiredAttributeType }}] {% endif %}{{ parameter.Type }} {{ parameter.VariableName }}{% if GenerateOptionalParameters and parameter.IsOptional %} = null{% endif %}{% if parameter.IsLast == false or UseCancellationToken %}, {% endif %}{% endfor %}{% if UseCancellationToken %}System.Threading.CancellationToken cancellationToken{% endif %})
    {
{%-         if IsAspNetCore and operation.WrapResponse %}
        var result = await _implementation.{{ operation.ActualOperationName }}Async({% for parameter in operation.Parameters %}{{ parameter.VariableName }}{% if parameter.HasDefault %} ?? {{parameter.Default}}{% endif %}{% if parameter.IsLast == false or UseCancellationToken %}, {% endif %}{% endfor %}{% if UseCancellationToken %}cancellationToken{% endif %}).ConfigureAwait(false);

        var status = result.StatusCode;
        Microsoft.AspNetCore.Mvc.ObjectResult response = new Microsoft.AspNetCore.Mvc.ObjectResult(result{% if operation.UnwrappedResultType != "void" %}.Result{% endif %}) { StatusCode = status };

        foreach (var header in result.Headers)
            Request.HttpContext.Response.Headers.Add(header.Key, new Microsoft.Extensions.Primitives.StringValues(header.Value.ToArray()));

        return response;
{%-         elsif operation.WrapResponse %}
        var result = await _implementation.{{ operation.ActualOperationName }}Async({% for parameter in operation.Parameters %}{{ parameter.VariableName }}{% if parameter.HasDefault %} ?? {{parameter.Default}}{% endif %}{% if parameter.IsLast == false or UseCancellationToken %}, {% endif %}{% endfor %}{% if UseCancellationToken %}cancellationToken{% endif %}).ConfigureAwait(false);

        var status = (System.Net.HttpStatusCode)result.StatusCode;
        HttpResponseMessage response = Request.CreateResponse(status{% if operation.UnwrappedResultType != "void" %}, result.Result{% endif %});

        foreach (var header in result.Headers)
            response.Headers.Add(header.Key, header.Value);

        return response;
{%-         else %}
        return _implementation.{{ operation.ActualOperationName }}Async({% for parameter in operation.Parameters %}{{ parameter.VariableName }}{% if parameter.HasDefault %} ?? {{parameter.Default}}{% endif %}{% if parameter.IsLast == false or UseCancellationToken %}, {% endif %}{% endfor %}{% if UseCancellationToken %}cancellationToken{% endif %});
{%         endif -%}
    }

{%     endfor -%}
}
{% elsif GenerateAbstractControllers -%}
{% template Controller.Class.Annotations %}
public abstract class {{ Class }}ControllerBase : {% if HasBaseClass %}{{ BaseClass }}{% else %}{{ AspNetNamespace }}.{% if IsAspNetCore %}ControllerBase{% else %}ApiController{% endif %}{% endif %}
{
{%     for operation in Operations -%}
{%         if operation.HasSummary -%}
    /// <summary>
    /// {{ operation.Summary | csharpdocs }}
    /// </summary>
{%         endif -%}
{%         if operation.HasDescription -%}
    /// <remarks>
    /// {{ operation.Description | csharpdocs }}
    /// </remarks>
{%         endif -%}
{%         for parameter in operation.Parameters -%}
{%             if parameter.HasDescription -%}
    /// <param name="{{ parameter.VariableName }}">{{ parameter.Description | csharpdocs }}</param>
{%             endif -%}
{%         endfor -%}
{%         if operation.HasResultDescription -%}
    /// <returns>{{ operation.ResultDescription | csharpdocs }}</returns>
{%         endif -%}
{%         if operation.IsDeprecated -%}
    [System.Obsolete]
{%         endif -%}
    {% template Controller.Method.Annotations %}
    [{{ AspNetNamespace }}.Http{{ operation.HttpMethodUpper }}, {{ AspNetNamespace }}.Route("{{ operation.Path }}"{% if operation.HasRouteName %}, Name = "{{ operation.RouteName }}"{% endif %})]
    public abstract {%  if operation.WrapResponse %}System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>{% else %}{{ operation.ResultType }}{% endif %} {{ operation.ActualOperationName }}({% for parameter in operation.Parameters %}{% if parameter.IsQuery %}[{{ AspNetNamespace }}.{% if IsAspNetCore -%}FromQuery{% else -%}FromUri{%- endif %}{% if parameter.IsValidIdentifier == false %}(Name = "{{ parameter.Name }}"){% endif %}] {% endif %}{% if parameter.IsHeader %}[{% if IsAspNetCore -%}{{ AspNetNamespace }}.{%- endif %}FromHeader{% if parameter.IsValidIdentifier == false %}(Name = "{{ parameter.Name }}"){% endif %}] {% endif %}{% if parameter.IsBody and parameter.IsBinaryBody == false %}[{{ AspNetNamespace }}.FromBody] {% endif %}{% if GenerateModelValidationAttributes and parameter.IsRequired %}[{{ RequiredAttributeType }}] {% endif %}{{ parameter.Type }} {{ parameter.VariableName }}{% if parameter.HasDefault %} = {{parameter.Default}}{% endif %}{% if GenerateOptionalParameters and parameter.IsOptional and parameter.HasDefault == false %} = null{% endif %}{% if parameter.IsLast == false or UseCancellationToken %}, {% endif %}{% endfor %}{% if UseCancellationToken %}System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken){% endif %});

{%     endfor -%}
}
{%- endif %}
