<?php

require __DIR__ . '/vendor/autoload.php';

if (empty($_GET['id'])) {
    echo(json_encode([]));
    die();
}

$config = include __DIR__ . '/config.php';
$internal_pics_dir = realpath(__DIR__ . $config['pics_dir']);
$app = new Phlaym\Roastmonday\Roastmonday($config, $internal_pics_dir);
$app->authenticateServerToken();
$parameters = [
    'include_html' => false,
    'include_counts' => false,
    'include_presence' => true,
    'include_raw' => false,
    'include_user_raw' => false
];
$resp = ['success' => false, 'error' => 0, 'text' => ''];
$ids = explode(",", $_GET['id']);
if (count($ids) == 1) {
    // TODO: Split up by multiple ids
} else {

}
try {
    $user = $app->getUser($ids[0], $parameters);
} catch (APnutI\Exceptions\NotFoundException $e) {
    $resp['error'] = 404;
} catch (Exception $e) {
    $resp['error'] = 500;
    $resp['text'] = 'Something went wrong';
}
if (!empty($user)) {
    $resp['success'] = true;
    $resp['error'] = 0;
    $resp['name'] = $user->name;
    $resp['presence'] = $user->getPresenceInt();
    $resp['presenceString'] = $user->getPresenceString();
}
echo json_encode($resp);
