<?php

namespace App\Listeners;

use App\Events\DomainProvisioningCompleted;
use App\Events\ProductProvisioningCompleted;
use App\Services\ProvisioningStatusService;

class UpdateProvisioningLogCompleted
{
    protected ProvisioningStatusService $provisioningStatus;

    public function __construct(ProvisioningStatusService $provisioningStatus)
    {
        $this->provisioningStatus = $provisioningStatus;
    }

    /**
     * Handle the event.
     */
    public function handle(ProductProvisioningCompleted|DomainProvisioningCompleted $event): void
    {
        $provisioningId = $event->provisioningId;

        // Update status in Redis
        $this->provisioningStatus->markAsCompleted(
            $provisioningId,
            $event->result ?? [],
            'İşlem başarıyla tamamlandı'
        );
    }
}
