// <auto-generated>
// DO NOT EDIT: generated by fsdgencsharp
// </auto-generated>
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Net.Http;
using Facility.Core;
using Facility.Core.Http;

#pragma warning disable 612, 618 // member is obsolete

namespace OapApi.v1.Client.Http
{
	[System.CodeDom.Compiler.GeneratedCode("fsdgencsharp", "")]
	public static partial class OapApiV1HttpMapping
	{
		/// <summary>
		/// Gets applications for the current user.
		/// </summary>
		public static readonly HttpMethodMapping<GetApplicationsRequestDto, GetApplicationsResponseDto> GetApplicationsMapping =
			new HttpMethodMapping<GetApplicationsRequestDto, GetApplicationsResponseDto>.Builder
			{
				HttpMethod = HttpMethod.Get,
				Path = "/applications",
				GetUriParameters = request =>
					new Dictionary<string, string>
					{
						{ "status", request.Status == null ? null : request.Status.Value.ToString() },
						{ "limit", request.Limit == null ? null : request.Limit.Value.ToString(CultureInfo.InvariantCulture) },
						{ "nextToken", request.NextToken },
					},
				SetUriParameters = (request, parameters) =>
				{
					parameters.TryGetValue("status", out var queryParameterStatus);
					request.Status = queryParameterStatus == null ? default(ApplicationStatus?) : new ApplicationStatus(queryParameterStatus);
					parameters.TryGetValue("limit", out var queryParameterLimit);
					request.Limit = ServiceDataUtility.TryParseInt32(queryParameterLimit);
					parameters.TryGetValue("nextToken", out var queryParameterNextToken);
					request.NextToken = queryParameterNextToken;
					return request;
				},
				ResponseMappings =
				{
					new HttpResponseMapping<GetApplicationsResponseDto>.Builder
					{
						StatusCode = (HttpStatusCode) 200,
						ResponseBodyType = typeof(GetApplicationsResponseDto),
					}.Build(),
				},
			}.Build();

		/// <summary>
		/// Creates a new application for the current user.
		/// </summary>
		public static readonly HttpMethodMapping<CreateApplicationRequestDto, CreateApplicationResponseDto> CreateApplicationMapping =
			new HttpMethodMapping<CreateApplicationRequestDto, CreateApplicationResponseDto>.Builder
			{
				HttpMethod = HttpMethod.Post,
				Path = "/applications/",
				ValidateRequest = request =>
				{
					if (request.ApplicationCreateSet == null)
						return ServiceResult.Failure(ServiceErrors.CreateRequestFieldRequired("applicationCreateSet"));
					return ServiceResult.Success();
				},
				RequestBodyType = typeof(ApplicationCreateSetDto),
				GetRequestBody = request => request.ApplicationCreateSet,
				CreateRequest = body => new CreateApplicationRequestDto { ApplicationCreateSet = (ApplicationCreateSetDto) body },
				ResponseMappings =
				{
					new HttpResponseMapping<CreateApplicationResponseDto>.Builder
					{
						StatusCode = (HttpStatusCode) 200,
						ResponseBodyType = typeof(ApplicationDto),
						MatchesResponse = response => response.Application != null,
						GetResponseBody = response => response.Application,
						CreateResponse = body => new CreateApplicationResponseDto { Application = (ApplicationDto) body },
					}.Build(),
					new HttpResponseMapping<CreateApplicationResponseDto>.Builder
					{
						StatusCode = (HttpStatusCode) 201,
					}.Build(),
				},
			}.Build();

		/// <summary>
		/// Gets the specified application for the current user.
		/// </summary>
		public static readonly HttpMethodMapping<GetApplicationRequestDto, GetApplicationResponseDto> GetApplicationMapping =
			new HttpMethodMapping<GetApplicationRequestDto, GetApplicationResponseDto>.Builder
			{
				HttpMethod = HttpMethod.Get,
				Path = "/applications/{id}",
				ValidateRequest = request =>
				{
					if (string.IsNullOrEmpty(request.Id))
						return ServiceResult.Failure(ServiceErrors.CreateRequestFieldRequired("id"));
					return ServiceResult.Success();
				},
				GetUriParameters = request =>
					new Dictionary<string, string>
					{
						{ "id", request.Id },
					},
				SetUriParameters = (request, parameters) =>
				{
					parameters.TryGetValue("id", out var queryParameterId);
					request.Id = queryParameterId;
					return request;
				},
				ResponseMappings =
				{
					new HttpResponseMapping<GetApplicationResponseDto>.Builder
					{
						StatusCode = (HttpStatusCode) 200,
						ResponseBodyType = typeof(ApplicationDto),
						MatchesResponse = response => response.Application != null,
						GetResponseBody = response => response.Application,
						CreateResponse = body => new GetApplicationResponseDto { Application = (ApplicationDto) body },
					}.Build(),
					new HttpResponseMapping<GetApplicationResponseDto>.Builder
					{
						StatusCode = (HttpStatusCode) 304,
						MatchesResponse = response => response.NotModified.GetValueOrDefault(),
						CreateResponse = body => new GetApplicationResponseDto { NotModified = true },
					}.Build(),
				},
				GetResponseHeaders = response =>
					new Dictionary<string, string>
					{
						["eTag"] = response.ETag,
					},
				SetResponseHeaders = (response, headers) =>
				{
					headers.TryGetValue("eTag", out var headerETag);
					response.ETag = headerETag;
					return response;
				},
			}.Build();

		/// <summary>
		/// Updates the application.
		/// </summary>
		public static readonly HttpMethodMapping<UpdateApplicationRequestDto, UpdateApplicationResponseDto> UpdateApplicationMapping =
			new HttpMethodMapping<UpdateApplicationRequestDto, UpdateApplicationResponseDto>.Builder
			{
				HttpMethod = new HttpMethod("PATCH"),
				Path = "/applications/{id}",
				ValidateRequest = request =>
				{
					if (string.IsNullOrEmpty(request.Id))
						return ServiceResult.Failure(ServiceErrors.CreateRequestFieldRequired("id"));
					if (request.ApplicationChangeSet == null)
						return ServiceResult.Failure(ServiceErrors.CreateRequestFieldRequired("applicationChangeSet"));
					return ServiceResult.Success();
				},
				GetUriParameters = request =>
					new Dictionary<string, string>
					{
						{ "id", request.Id },
					},
				SetUriParameters = (request, parameters) =>
				{
					parameters.TryGetValue("id", out var queryParameterId);
					request.Id = queryParameterId;
					return request;
				},
				RequestBodyType = typeof(ApplicationChangeSetDto),
				GetRequestBody = request => request.ApplicationChangeSet,
				CreateRequest = body => new UpdateApplicationRequestDto { ApplicationChangeSet = (ApplicationChangeSetDto) body },
				ResponseMappings =
				{
					new HttpResponseMapping<UpdateApplicationResponseDto>.Builder
					{
						StatusCode = (HttpStatusCode) 200,
						ResponseBodyType = typeof(ApplicationDto),
						MatchesResponse = response => response.Application != null,
						GetResponseBody = response => response.Application,
						CreateResponse = body => new UpdateApplicationResponseDto { Application = (ApplicationDto) body },
					}.Build(),
				},
			}.Build();
	}
}
