<?php
declare(strict_types=1);

/**
 * DELETE /api/email/messages/{id}
 * Permanent delete (EXPUNGE).
 */

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

require_once __DIR__ . '/_bootstrap.php';

use Oscar\MailEngine\ImapClient\InMemoryImapClient;

try {
    $messageId = $_SERVER['FRESH_ROUTE_PARAMS']['id'] ?? null;
    if (!$messageId) {
        throw new \InvalidArgumentException('Message ID is required');
    }
    $accountId = 'acc1';
    $imap = new InMemoryImapClient();
    $imap->delete($messageId, $accountId);
    echo json_encode(['ok' => true]);
} catch (\Throwable $e) {
    http_response_code(500);
    echo json_encode(['error' => $e->getMessage()]);
}
