#include "StdAfx.h"
#include "PlayFab<%- api.name %>Api.h"
#include "PlayFabSettings.h"

using namespace PlayFab;
using namespace <%- api.name %>Models;
<% if(hasClientOptions) { %>
// Client-Specific
Aws::String PlayFabClientApi::mUserSessionTicket;

bool PlayFabClientApi::IsClientLoggedIn()
{
    return mUserSessionTicket.length() != 0;
}

void PlayFabClientApi::MultiStepClientLogin(bool needsAttribution)
{
    if (needsAttribution && !PlayFabSettings::playFabSettings.disableAdvertising && PlayFabSettings::playFabSettings.advertisingIdType.length() > 0 && PlayFabSettings::playFabSettings.advertisingIdValue.length() > 0)
    {
        AttributeInstallRequest request;
        if (PlayFabSettings::playFabSettings.advertisingIdType == PlayFabSettings::playFabSettings.AD_TYPE_IDFA)
            request.Idfa = PlayFabSettings::playFabSettings.advertisingIdValue;
        else if (PlayFabSettings::playFabSettings.advertisingIdType == PlayFabSettings::playFabSettings.AD_TYPE_ANDROID_ID)
            request.Adid = PlayFabSettings::playFabSettings.advertisingIdValue;
        else
            return;
        AttributeInstall(request, nullptr, nullptr);
    }
}
<% } %>
// PlayFab<%- api.name %> Api
PlayFab<%- api.name %>Api::PlayFab<%- api.name %>Api() {}
<% for(var i in api.calls) { var apiCall = api.calls[i]; %>
void PlayFab<%- api.name %>Api::<%- apiCall.name %>(
<% if(HasRequest(apiCall, api)) { %>    <%- apiCall.request %>& request,<% } %>
    ProcessApiCallback<<%- apiCall.result %>> callback,
    ErrorCallback errorCallback,
    void* customData
    )
{
<%- GetRequestActions(apiCall, api) %>
<% if(HasRequest(apiCall, api)) {
%>    PlayFabRequest* newRequest = new PlayFabRequest(PlayFabSettings::playFabSettings.getURL("<%- apiCall.url %>"), Aws::Http::HttpMethod::HTTP_<%- apiCall.method %>, <%- GetAuthParams(apiCall) %>, request.toJSONString(), customData, callback, errorCallback, On<%- apiCall.name %>Result);
<% } else {
%>    PlayFabRequest* newRequest = new PlayFabRequest(PlayFabSettings::playFabSettings.getURL("<%- apiCall.url %>"), Aws::Http::HttpMethod::HTTP_<%- apiCall.method %>, <%- GetAuthParams(apiCall) %>, "", customData, callback, errorCallback, On<%- apiCall.name %>Result);
<% } %>    PlayFabRequestManager::playFabHttp.AddRequest(newRequest);
}

void PlayFab<%- api.name %>Api::On<%- apiCall.name %>Result(PlayFabRequest* request)
{
    if (PlayFabBaseModel::DecodeRequest(request))
    {
        <%- apiCall.result %>* outResult = new <%- apiCall.result %>;
        outResult->readFromValue(request->mResponseJson->FindMember("data")->value);

<%- GetResultActions(apiCall, api) %>
        if (request->mResultCallback != nullptr)
        {
            ProcessApiCallback<<%- apiCall.result %>> successCallback = reinterpret_cast<ProcessApiCallback<<%- apiCall.result %>>>(request->mResultCallback);
            successCallback(*outResult, request->mCustomData);
        }
        delete outResult;
        delete request;
    }
}
<% } %>
