<?php

namespace App\Jobs;

use App\Enums\ApprovalStatusEnum;
use App\Models\Article;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;

class CleanupArticlesJob implements ShouldQueue
{
    use Queueable;

    private const RETENTION_DAYS = 30;

    public function handle(): void
    {
        Article::where('created_at', '<', now()->subDays(self::RETENTION_DAYS))
            ->whereDoesntHave('routeArticles', fn ($q) => $q->whereIn('approval_status', [
                ApprovalStatusEnum::PENDING,
                ApprovalStatusEnum::APPROVED,
            ]))
            ->delete();
    }
}
