<?php
declare(strict_types=1);

namespace App\Modules\MatchCenter\Models;

use App\Core\Model;
use App\Core\App;

class MatchEvent extends Model
{
    protected static string $table = 'match_events';
    protected static bool $softDelete = false;
    protected static bool $timestamps = false;
    protected static bool $autoTrackAuthor = false;
    protected static array $fillable = [
        'match_id',
        'minute',
        'event_type',
        'team',
        'player_name',
        'description_ar',
    ];

    /**
     * Get all events for a given match, sorted by minute.
     */
    public static function getByMatch(int $matchId): array
    {
        $db = App::getInstance()->db();
        return $db->select(
            "SELECT * FROM match_events WHERE match_id = ? ORDER BY minute ASC, created_at ASC",
            [$matchId]
        );
    }

    /**
     * Get event type labels in Arabic.
     */
    public static function getEventTypeLabels(): array
    {
        return [
            'goal'         => 'هدف',
            'foul'         => 'خطأ',
            'yellow_card'  => 'بطاقة صفراء',
            'red_card'     => 'بطاقة حمراء',
            'substitution' => 'تبديل',
            'penalty'      => 'ركلة جزاء',
            'injury'       => 'إصابة',
            'half_time'    => 'نهاية الشوط الأول',
            'full_time'    => 'نهاية المباراة',
            'other'        => 'أخرى',
        ];
    }

    /**
     * Get event type icon (Lucide icon name).
     */
    public static function getEventTypeIcon(string $type): string
    {
        return match ($type) {
            'goal'         => 'circle-dot',
            'foul'         => 'alert-triangle',
            'yellow_card'  => 'square',
            'red_card'     => 'square',
            'substitution' => 'repeat',
            'penalty'      => 'target',
            'injury'       => 'heart-pulse',
            'half_time'    => 'pause',
            'full_time'    => 'flag-checkered',
            default        => 'info',
        };
    }

    /**
     * Get event type color.
     */
    public static function getEventTypeColor(string $type): string
    {
        return match ($type) {
            'goal'         => '#10B981',
            'foul'         => '#F59E0B',
            'yellow_card'  => '#EAB308',
            'red_card'     => '#DC2626',
            'substitution' => '#6366F1',
            'penalty'      => '#8B5CF6',
            'injury'       => '#EF4444',
            'half_time'    => '#6B7280',
            'full_time'    => '#6B7280',
            default        => '#9CA3AF',
        };
    }
}
