<?php

namespace App\EventHooks\Service;

use App\EventHooks\HookEvent;
use App\Models\ClientProduct;

/**
 * Fire noktası: Admin\ClientController::productUpdate — admin bir hizmetin
 * yapılandırılabilir-seçenek (config option) değerlerini güncellediğinde →
 * AfterConfigOptionsUpgrade. Gap (Task 11) — fire zaten mevcuttu, tipli event eklendi.
 * Context: upgradeid (= service id), serviceid, userid (= client id),
 *   configoptions (option_id => value_id map).
 */
class ConfigOptionsUpgraded extends HookEvent
{
    public const HOOK = 'AfterConfigOptionsUpgrade';

    public function service(): ?ClientProduct
    {
        $id = $this->get('serviceid') ?? $this->get('upgradeid');

        return $id ? ClientProduct::find($id) : null;
    }

    /** Uygulanan config-option seçimleri (option_id => value_id). */
    public function configOptions(): array
    {
        $opts = $this->get('configoptions');

        return is_array($opts) ? $opts : [];
    }
}
