<?php

namespace App\Console\Commands;

use App\Modules\Pilkades\Models\VisitorLog;
use Illuminate\Console\Command;

class PurgeVisitorLogs extends Command
{
    protected $signature = 'pilkades:purge-visitor-logs {--months=12 : Retention period in months}';

    protected $description = 'Delete visitor_logs older than the retention period (default 12 months)';

    public function handle(): int
    {
        $months = (int) $this->option('months');
        $cutoff = now()->subMonths($months);

        $deleted = VisitorLog::withoutGlobalScopes()->where('visited_at', '<', $cutoff)->delete();

        $this->info("Purged {$deleted} visitor_logs older than {$cutoff->toDateString()}.");

        return self::SUCCESS;
    }
}
