<?php

namespace App\Domains\Analytics\Jobs;

use App\Domains\Analytics\Models\Click;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;

class PruneRawClicksJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable;

    public function handle(): void
    {
        Click::where('clicked_at', '<', now()->subDays(90))
            ->chunkById(1000, function ($clicks) {
                $clicks->toQuery()->delete();
            });
    }
}
