<?php
/**
 * GET /api/reports/mine.php
 * Returns the caller's own filed reports with current moderation status -
 * previously there was a way to SUBMIT a report but no way to see what
 * happened to it afterward.
 */

require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../includes/response.php';
require_once __DIR__ . '/../includes/auth.php';

$userId = require_login();

$pdo = Database::connect();
$stmt = $pdo->prepare('
    SELECT r.id, r.reason, r.status, r.created_at,
           p.id AS product_id, p.name AS product_name,
           ru.email AS reported_user_email
    FROM reports r
    LEFT JOIN products p ON p.id = r.product_id
    LEFT JOIN users ru ON ru.id = r.reported_user_id
    WHERE r.reported_by = ?
    ORDER BY r.created_at DESC
');
$stmt->execute([$userId]);

send_json(true, 'OK', ['reports' => $stmt->fetchAll()]);
