<?php

namespace App\Console\Commands;

use App\Domain\Audit\Models\AuditLog;
use Illuminate\Console\Command;

class CleanupAuditLogs extends Command
{
    protected $signature = 'audit:cleanup {--days=365 : Days to retain non-financial logs}';

    protected $description = 'Remove non-financial audit logs older than retention period';

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

        $deleted = AuditLog::where('is_financial', false)
            ->where('created_at', '<', $cutoff)
            ->delete();

        $this->info("Deleted {$deleted} expired non-financial audit log(s).");

        return self::SUCCESS;
    }
}
