<?php
namespace App\Jobs\Operations;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Cache;

final class RecordSecurityMetricJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    public function __construct(public string $metric, public int $value = 1, public array $labels = []) { $this->onQueue('notifications'); }
    public function handle(): void
    {
        $key = 'metrics:'.$this->metric.':'.hash('sha256', json_encode($this->labels));
        Cache::store('redis')->increment($key, $this->value);
        Cache::store('redis')->put($key.':labels', $this->labels, now()->addDays(2));
    }
}
