// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// WARNING! Do not edit this file manually, your changes will be overwritten.

#include "ClientClient.h"

#include "graphqlservice/internal/SortedMap.h"

#include <algorithm>
#include <array>
#include <sstream>
#include <stdexcept>
#include <string_view>
#include <utility>

using namespace std::literals;

namespace graphql::client {
namespace graphql {

const std::string& GetRequestText() noexcept
{
	static const auto s_request = R"gql(
		query GetWaitlist {
		  getWaitlist {
		    email
		    firstName
		    lastName
		  }
		}
	)gql"s;

	return s_request;
}

const peg::ast& GetRequestObject() noexcept
{
	static const auto s_request = []() noexcept {
		auto ast = peg::parseString(GetRequestText());

		// This has already been validated against the schema by clientgen.
		ast.validated = true;

		return ast;
	}();

	return s_request;
}

} // namespace graphql

using namespace graphql;

template <>
query::GetWaitlist::Response::getWaitlist_WaitlistEntry Response<query::GetWaitlist::Response::getWaitlist_WaitlistEntry>::parse(response::Value&& response)
{
	query::GetWaitlist::Response::getWaitlist_WaitlistEntry result;

	if (response.type() == response::Type::Map)
	{
		auto members = response.release<response::MapType>();

		for (auto& member : members)
		{
			if (member.first == R"js(email)js"sv)
			{
				result.email = ModifiedResponse<std::string>::parse(std::move(member.second));
				continue;
			}
			if (member.first == R"js(firstName)js"sv)
			{
				result.firstName = ModifiedResponse<std::string>::parse<TypeModifier::Nullable>(std::move(member.second));
				continue;
			}
			if (member.first == R"js(lastName)js"sv)
			{
				result.lastName = ModifiedResponse<std::string>::parse<TypeModifier::Nullable>(std::move(member.second));
				continue;
			}
		}
	}

	return result;
}

namespace query::GetWaitlist {

const std::string& GetOperationName() noexcept
{
	static const auto s_name = R"gql(GetWaitlist)gql"s;

	return s_name;
}

Response parseResponse(response::Value&& response)
{
	Response result;

	if (response.type() == response::Type::Map)
	{
		auto members = response.release<response::MapType>();

		for (auto& member : members)
		{
			if (member.first == R"js(getWaitlist)js"sv)
			{
				result.getWaitlist = ModifiedResponse<query::GetWaitlist::Response::getWaitlist_WaitlistEntry>::parse<TypeModifier::List>(std::move(member.second));
				continue;
			}
		}
	}

	return result;
}

[[nodiscard("unnecessary call")]] const std::string& Traits::GetRequestText() noexcept
{
	return graphql::GetRequestText();
}

[[nodiscard("unnecessary call")]] const peg::ast& Traits::GetRequestObject() noexcept
{
	return graphql::GetRequestObject();
}

[[nodiscard("unnecessary call")]] const std::string& Traits::GetOperationName() noexcept
{
	return GetWaitlist::GetOperationName();
}

[[nodiscard("unnecessary conversion")]] Traits::Response Traits::parseResponse(response::Value&& response)
{
	return GetWaitlist::parseResponse(std::move(response));
}

} // namespace query::GetWaitlist
} // namespace graphql::client
