<?php

if (!function_exists('format_tip_match_leg')) {
    /**
     * Build a tip match leg array from form/API input.
     */
    function format_tip_match_leg(array $match): array
    {
        $leg = [
            'team1' => $match['team1'],
            'team2' => $match['team2'],
            'league' => $match['league'] ?? '',
            'prediction' => $match['prediction'] ?? null,
            'odds' => $match['odds'],
        ];

        if (!empty($match['fixture_id'])) {
            $leg['fixture_id'] = (int) $match['fixture_id'];
        }
        if (!empty($match['kickoff'])) {
            $leg['kickoff'] = $match['kickoff'];
        }

        foreach (['team1_logo', 'team2_logo', 'league_logo'] as $logoField) {
            if (!empty($match[$logoField])) {
                $leg[$logoField] = $match[$logoField];
            }
        }

        return $leg;
    }
}

if (!function_exists('enrich_match_leg_with_logos')) {
    /**
     * @param array<string, mixed> $leg
     * @return array<string, mixed>
     */
    function enrich_match_leg_with_logos(array $leg): array
    {
        return (new \App\Libraries\FootballMatchLogoResolver())->enrichLeg($leg);
    }
}

if (!function_exists('enrich_match_legs_with_logos')) {
    /**
     * @param list<array<string, mixed>> $legs
     * @return list<array<string, mixed>>
     */
    function enrich_match_legs_with_logos(array $legs): array
    {
        return (new \App\Libraries\FootballMatchLogoResolver())->enrichLegs($legs);
    }
}
