<?php

require_once __DIR__ . '/../../../config/database.php';
require_once __DIR__ . '/../../../config/helpers.php';
require_once __DIR__ . '/../../../middleware/admin.php';
require_once __DIR__ . '/MailboxRepository.php';

requireAdmin();
global $pdo;
$route = getApiRouteSegments();
$id = isset($route[2]) ? (int) $route[2] : 0;
if ($id <= 0) {
    jsonResponse(false, 'mailboxes.invalid_id', null, 422);
}

$repo = new MailboxRepository($pdo);
$current = $repo->findById($id);
if (!$current) {
    jsonResponse(false, 'mailboxes.not_found', null, 404);
}

$repo->delete($id);
jsonResponse(true, 'mailboxes.deleted', ['id' => $id]);
