<?php

// Get today's champion based on day of week
function getTodaysChampion($pdo) {
    $dow = date('w'); // 0 = Sunday
    $stmt = $pdo->prepare("SELECT * FROM champions WHERE day_of_week = ?");
    $stmt->execute([$dow]);
    return $stmt->fetch();
}

// XP calculation rules
function calculateXP($frequency, $isBounty) {
    if ($isBounty) return 50;

    switch ($frequency) {
        case 'daily': return 5;
        case 'weekly': return 10;
        case 'fortnightly': return 15;
        case 'monthly': return 20;
        case 'one_off': return 25;
        default: return 5;
    }
}

// Add XP to champion
function addXP($pdo, $champion_id, $xp) {
    // Update total XP
    $stmt = $pdo->prepare("
        UPDATE champion_stats
        SET total_xp = total_xp + ?, last_updated = NOW()
        WHERE champion_id = ?
    ");
    $stmt->execute([$xp, $champion_id]);

    // Recalculate level
    $stmt = $pdo->prepare("
        UPDATE champion_stats
        SET level = FLOOR(total_xp / 100) + 1
        WHERE champion_id = ?
    ");
    $stmt->execute([$champion_id]);
}

// Get all champions (for dropdowns, inventory assignment, etc.)
function getAllChampions($pdo) {
    $stmt = $pdo->query("SELECT * FROM champions ORDER BY day_of_week ASC");
    return $stmt->fetchAll();
}

?>