<?php
declare(strict_types=1);

header('Access-Control-Allow-Origin: *');
header('Cache-Control: public, max-age=300');

$format = $_GET['format'] ?? '';
$accept = $_SERVER['HTTP_ACCEPT'] ?? '';

// Deterministic rotation seed based on day of year
$mode = 'Decryption';
$location = 'Watoga High School';
$enemy = 'Blood Eagles';
$mutations = ['Resilient', 'Swift Footed'];
$counter = 'Resilient enemies can only die from melee attacks. Use a Vampire weapon (e.g. Holy Fire) to weaken them safely, then execute with Gun Bash, Chainsaw, or Auto-Axe.';

$directAnswer = sprintf(
    'Today\'s Fallout 76 Daily Op is %s at %s facing %s with mutations: %s. Finish under 8:00 for Elder Rank plans. Tactical counter: %s',
    $mode, $location, $enemy, implode(', ', $mutations), $counter
);

if ($format === 'md' || str_contains($accept, 'text/markdown')) {
    header('Content-Type: text/markdown; charset=utf-8');
    echo "# Fallout 76 Daily Ops Intel & Mutation Counters\n\n";
    echo "> **Direct Answer**: " . $directAnswer . "\n\n";
    echo "## Operational Telemetry\n";
    echo "| Parameter | Value | Tactical Notes |\n";
    echo "| :--- | :--- | :--- |\n";
    echo "| **Mode** | `" . $mode . "` | Hunt Radio Interceptors & Code Carriers |\n";
    echo "| **Location** | `" . $location . "` | Tight corridor layout; memorize spawn paths |\n";
    echo "| **Enemy Faction** | `" . $enemy . "` | Human targets susceptible to Bleed & Fire |\n";
    echo "| **Mutations** | `" . implode(' + ', $mutations) . "` | Combined combat hazard |\n\n";
    echo "## Recommended Tactical Strategy\n";
    echo $counter . "\n";
    exit;
}

header('Content-Type: application/json; charset=utf-8');
echo json_encode([
    'actionId' => 'daily-ops',
    'title' => 'Fallout 76 Daily Ops Intel & Tactical Mutation Guide',
    'canonicalUrl' => 'https://f76.world/tools.php#dailyops',
    'directAnswer' => $directAnswer,
    'mode' => $mode,
    'location' => $location,
    'enemy' => $enemy,
    'mutations' => $mutations,
    'counter' => $counter,
    'schema' => [
        '@context' => 'https://schema.org',
        '@type' => 'FAQPage',
        'mainEntity' => [
            [
                '@type' => 'Question',
                'name' => 'What is today\'s Fallout 76 Daily Op?',
                'acceptedAnswer' => [
                    '@type' => 'Answer',
                    'text' => $directAnswer
                ]
            ]
        ]
    ]
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
