<?php
declare(strict_types=1);

/**
 * PUT /api/email/accounts/{id}/active
 * Switch the active account. Body: {}.
 */

header('Content-Type: application/json');

require_once __DIR__ . '/_bootstrap.php';

use FreshCloud\Mail\Identity\InMemoryIdentityProvider;

try {
    $userId = 'user123'; // TODO v0.2.0: get from auth
    $identity = new InMemoryIdentityProvider();
    $identity->setActiveAccountId($userId, $_SERVER['FRESH_ROUTE_PARAMS']['id'] ?? 'acc1');

    echo json_encode(['ok' => true, 'active_id' => $identity->getActiveAccountId($userId)]);
} catch (\Throwable $e) {
    http_response_code(500);
    echo json_encode(['error' => $e->getMessage()]);
}
