<?php
require_once __DIR__ . '/../../config/bootstrap.php';

use App\Services\AuthService;
use App\Services\SignatureService;

$auth = new AuthService();

$signatureId = (int) ($_GET['id'] ?? 0);
$type = $_GET['type'] ?? '';

$signatureService = new SignatureService();
$imagePath = $signatureService->getImage($signatureId, $type);

if ($imagePath && file_exists($imagePath)) {
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $mimeType = finfo_file($finfo, $imagePath);
    finfo_close($finfo);

    header('Content-Type: ' . $mimeType);
    header('Content-Length: ' . filesize($imagePath));
    readfile($imagePath);
} else {
    header('HTTP/1.1 404 Not Found');
    echo "Imagen no encontrada";
}
