<?php

namespace App\Console\Commands;

use App\Models\Entry;
use App\Models\News;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;

#[Signature('entries:purge-rejected {--days=7}')]
#[Description('Soft Delete rejected entries older than X days')]
class DeleteRejectedEntries extends Command
{
    /**
     * Execute the console command.
     */
    public function handle()
    {
        $days = (int) $this->option('days');
        $count = Entry::where('state', 'rejected')
                    ->where('rejected_at', '<', now()->subDays($days))
                    ->delete();
        $count += News::where('state', 'rejected')
            ->where('rejected_at', '<', now()->subDays($days))
            ->delete();

        $this->info("Deleted {$count} entries/news");
        return self::SUCCESS;
    }
}
