<?php
declare(strict_types=1);

require_once __DIR__ . '/../../system/bootstrap.php';
require_once __DIR__ . '/../../system/auth.php';

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

$user = require_auth($pdo);

$stmt = $pdo->prepare("
    SELECT
        id AS declaration_id,
        declaration_number,
        status,
        created_at,
        locked_at
    FROM md_declarations
    WHERE created_by = :user_id
    ORDER BY created_at DESC
");

$stmt->execute([
    'user_id' => (int)$user['id']
]);

$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo json_encode($rows);
