<?php

namespace App\Commands;

use App\Libraries\FootballLeagueSync;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;

class FootballPruneFixtures extends BaseCommand
{
    protected $group = 'Football';
    protected $name = 'football:prune-fixtures';
    protected $description = 'Remove fixtures outside the rolling date window';
    protected $usage = 'football:prune-fixtures [daysPast] [daysFuture]';

    public function run(array $params)
    {
        $daysPast = (int) ($params[0] ?? 30);
        $daysFuture = (int) ($params[1] ?? 60);

        try {
            $sync = new FootballLeagueSync();
            $removed = $sync->pruneOldFixtures($daysPast, $daysFuture);
            CLI::write("Removed {$removed} fixture row(s).", 'green');
        } catch (\Throwable $e) {
            CLI::error($e->getMessage());
            return EXIT_ERROR;
        }

        return EXIT_SUCCESS;
    }
}
