<?php

set_include_path(__DIR__.'/../../HelixWebServices/lib');

// thj: I have no idea if there's a better way of doing this in PHP.
include 'ApiClient.php';
include 'ApiException.php';
include 'Configuration.php';
include 'ObjectSerializer.php';
include 'Api/AlphaApi.php';
include 'Api/DefaultApi.php';
include 'Model/BranchCommand.php';
include 'Model/BranchesCommand.php';
include 'Model/ChangeCommand.php';
include 'Model/ChangelistAction.php';
include 'Model/ChangelistRequest.php';
include 'Model/ChangesCommand.php';
include 'Model/ClientCommand.php';
include 'Model/ClientsCommand.php';
include 'Model/CommandRequest.php';
include 'Model/CommandResponse.php';
include 'Model/Counter.php';
include 'Model/DepotCommand.php';
include 'Model/DepotsCommand.php';
include 'Model/DirsCommand.php';
include 'Model/FilesCommand.php';
include 'Model/FstatCommand.php';
include 'Model/GitFusionRepoBranchConfig.php';
include 'Model/GitFusionRepoConfig.php';
include 'Model/GitFusionRepoGlobalOverrides.php';
include 'Model/GitFusionRepoId.php';
include 'Model/GroupCommand.php';
include 'Model/GroupsCommand.php';
include 'Model/HWSStatus.php';
include 'Model/JobCommand.php';
include 'Model/JobsCommand.php';
include 'Model/LabelCommand.php';
include 'Model/LabelsCommand.php';
include 'Model/Location.php';
include 'Model/LoginRequest.php';
include 'Model/LoginResponse.php';
include 'Model/P4dConfigId.php';
include 'Model/Protections.php';
include 'Model/ServerCommand.php';
include 'Model/ServerLoginRequest.php';
include 'Model/ServersCommand.php';
include 'Model/StreamCommand.php';
include 'Model/StreamsCommand.php';
include 'Model/Triggers.php';
include 'Model/UserCommand.php';
include 'Model/UsersCommand.php';

use HelixWebServices\Api\DefaultApi;

function apiNoAuth()
{
    $api = new DefaultApi();
    $api->getApiClient()->getConfig()->setHost("http://localhost:9000/api");
    return $api;
}

function apiAsJDoe()
{
    $api = apiNoAuth();

    $login_request = new HelixWebServices\Model\LoginRequest();
    $login_request->setUser("jdoe");
    $login_request->setPassword("johndoe1A!");
    $login_response = $api->loginPost($login_request);

    $api->getApiClient()->getConfig()->setApiKey("Authorization", $login_response->getTicket());

    return $api;
}


function apiAsSuper()
{
    $api = apiNoAuth();

    $login_request = new HelixWebServices\Model\LoginRequest();
    $login_request->setUser("super");
    $login_request->setPassword("superuser1A!");
    $login_response = $api->loginPost($login_request);

    $api->getApiClient()->getConfig()->setApiKey("Authorization", $login_response->getTicket());

    return $api;
}


// PHP 5.3 Anonymous function as callback
// code is untested
assert_options(ASSERT_CALLBACK, function($file, $line, $code) {
    throw new Exception('Assert failed in $file on line $line');
});