<?php
declare(strict_types=1);

require_once __DIR__ . '/../../../config/database.php';
require_once __DIR__ . '/../../../core/Response.php';

$db = Database::getInstance();

if (empty($_GET['product_id'])) {
    Response::error('product_id is required', 422);
}

$productId = (int)$_GET['product_id'];

$stmt = $db->prepare("
    SELECT
        id,
        image_path,
        alt_text,
        caption,
        is_featured,
        sort_order,
        status
    FROM retail_product_images
    WHERE product_id = :pid
    ORDER BY sort_order ASC
");
$stmt->execute(['pid' => $productId]);

Response::success('Images fetched successfully', [
    'images' => $stmt->fetchAll(PDO::FETCH_ASSOC)
]);
