//----------------------
// <auto-generated>
//     Generated using the NSwag toolchain v{{ ToolchainVersion }} (http://NSwag.org)
// </auto-generated>
//----------------------

{% if GenerateNullableReferenceTypes -%}
#nullable enable

{%- endif %}
{% for usage in NamespaceUsages -%}
using {{ usage }};
{% endfor -%}

{% template File.Header %}

namespace {{ Namespace }}
{
    using System = global::System;

    {{ Clients | tab }}

{% if GenerateContracts -%}
    {{ Classes | tab }}

{%-     if RequiresFileParameterType -%}
    [System.CodeDom.Compiler.GeneratedCode("NSwag", "{{ ToolchainVersion }}")]
    public partial class FileParameter
    {
        public FileParameter(System.IO.Stream data)
            : this (data, null, null)
        {
        }

{%-          if GenerateNullableReferenceTypes -%}
        public FileParameter(System.IO.Stream data, string? fileName)
{%-          else -%}
        public FileParameter(System.IO.Stream data, string fileName)
{%-          endif -%}
            : this (data, fileName, null)
        {
        }

{%-          if GenerateNullableReferenceTypes -%}
        public FileParameter(System.IO.Stream data, string? fileName, string? contentType)
{%-          else -%}
        public FileParameter(System.IO.Stream data, string fileName, string contentType)
{%-          endif -%}
        {
            Data = data;
            FileName = fileName;
            ContentType = contentType;
        }

        public System.IO.Stream Data { get; private set; }

{%-          if GenerateNullableReferenceTypes -%}
        public string? FileName { get; private set; }

        public string? ContentType { get; private set; }
{%-          else -%}
        public string FileName { get; private set; }

        public string ContentType { get; private set; }
{%-          endif -%}
    }

{%-     endif %}
{%-     if GenerateFileResponseClass %}
    [System.CodeDom.Compiler.GeneratedCode("NSwag", "{{ ToolchainVersion }}")]
    public partial class FileResponse : System.IDisposable
    {
{%-          if GenerateNullableReferenceTypes -%}
        private System.IDisposable? _client;
        private System.IDisposable? _response;
{%-          else -%}
        private System.IDisposable _client;
        private System.IDisposable _response;
{%-          endif -%}

        public int StatusCode { get; private set; }

        public System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> Headers { get; private set; }

        public System.IO.Stream Stream { get; private set; }

        public bool IsPartial
        {
            get { return StatusCode == 206; }
        }

{%-          if GenerateNullableReferenceTypes -%}
        public FileResponse(int statusCode, System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> headers, System.IO.Stream stream, System.IDisposable? client, System.IDisposable? response)
{%-          else -%}
        public FileResponse(int statusCode, System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> headers, System.IO.Stream stream, System.IDisposable client, System.IDisposable response)
{%-          endif -%}
        {
            StatusCode = statusCode;
            Headers = headers;
            Stream = stream;
            _client = client;
            _response = response;
        }

        public void Dispose()
        {
            Stream.Dispose();
            if (_response != null)
                _response.Dispose();
            if (_client != null)
                _client.Dispose();
        }
    }

{%-     endif %}
{%-     if WrapResponses and GenerateResponseClasses %}
{%-         for responseClassName in ResponseClassNames %}
    [System.CodeDom.Compiler.GeneratedCode("NSwag", "{{ ToolchainVersion }}")]
    public partial class {{ responseClassName }}
    {
        public int StatusCode { get; private set; }

        public System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> Headers { get; private set; }

        public {{ responseClassName }}(int statusCode, System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> headers)
        {
            StatusCode = statusCode;
            Headers = headers;
        }
    }

    [System.CodeDom.Compiler.GeneratedCode("NSwag", "{{ ToolchainVersion }}")]
    public partial class {{ responseClassName }}<TResult> : {{ responseClassName }}
    {
        public TResult Result { get; private set; }

        public {{ responseClassName }}(int statusCode, System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> headers, TResult result)
            : base(statusCode, headers)
        {
            Result = result;
        }
    }

{%-        endfor %}
{%-     endif %}
{%-     if GenerateExceptionClasses %}
{%-         for exceptionClassName in ExceptionClassNames %}
    [System.CodeDom.Compiler.GeneratedCode("NSwag", "{{ ToolchainVersion }}")]
    public partial class {{ exceptionClassName }} : System.Exception
    {
        public int StatusCode { get; private set; }

{%-             if GenerateNullableReferenceTypes -%}
        public string? Response { get; private set; }
{%-              else -%}
        public string Response { get; private set; }
{%-              endif -%}

        public System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> Headers { get; private set; }

{%-              if GenerateNullableReferenceTypes -%}
        public {{ exceptionClassName }}(string message, int statusCode, string? response, System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> headers, System.Exception? innerException)
{%-              else -%}
        public {{ exceptionClassName }}(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> headers, System.Exception innerException)
{%-              endif -%}
            : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + ((response == null) ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException)
        {
            StatusCode = statusCode;
            Response = response;
            Headers = headers;
        }

        public override string ToString()
        {
            return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString());
        }
    }

    [System.CodeDom.Compiler.GeneratedCode("NSwag", "{{ ToolchainVersion }}")]
    public partial class {{ exceptionClassName }}<TResult> : {{ exceptionClassName }}
    {
        public TResult Result { get; private set; }

{%-              if GenerateNullableReferenceTypes -%}
        public {{ exceptionClassName }}(string message, int statusCode, string? response, System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> headers, TResult result, System.Exception? innerException)
{%-              else -%}
        public {{ exceptionClassName }}(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> headers, TResult result, System.Exception innerException)
{%-              endif -%}
            : base(message, statusCode, response, headers, innerException)
        {
            Result = result;
        }
    }

{%         endfor -%}
{%     endif -%}
{%- endif %}
{% if GenerateImplementation -%}
{%     if RequiresJsonExceptionConverter -%}
    {% template JsonExceptionConverter %}
{%     endif -%}
{%- endif %}

}

{% template File.Footer %}
