<?php
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');

require_once '../../core/bootstrap.php';

$fixture_id = filter_input(INPUT_GET, 'fixture_id', FILTER_VALIDATE_INT);

if (!$fixture_id) {
    http_response_code(400);
    echo json_encode(['message' => 'A valid fixture ID is required.']);
    exit();
}

$lineupModel = new Lineup();

try {
    $lineup = $lineupModel->getLineupByFixtureId($fixture_id);

    if (!$lineup) {
        http_response_code(404);
        echo json_encode(['message' => 'Lineup not found for this fixture.']);
        exit();
    }

    http_response_code(200);
    echo json_encode($lineup);

} catch (Exception $e) {
    http_response_code(500);
    echo json_encode(['message' => $e->getMessage()]);
}

?>