<?php

declare(strict_types=1);

namespace ImovelZapAi\Automation\Application\Services;

use ImovelZapAi\Automation\Domain\Enums\ActionKey;
use ImovelZapAi\Automation\Domain\Enums\ConditionOperator;
use ImovelZapAi\Automation\Domain\Enums\TriggerEventKey;

final class TriggerCatalog
{
    /** @return list<array{key: string, label: string, category: string, event_class: string}> */
    public function listTriggers(): array
    {
        return array_map(static fn (TriggerEventKey $key): array => [
            'key' => $key->value,
            'label' => $key->label(),
            'category' => $key->category(),
            'event_class' => $key->eventClass(),
        ], TriggerEventKey::cases());
    }

    /** @return list<string> */
    public static function eventClasses(): array
    {
        return array_map(static fn (TriggerEventKey $key): string => $key->eventClass(), TriggerEventKey::cases());
    }

    public static function keyForClass(string $class): ?string
    {
        return TriggerEventKey::fromEventClass($class)?->value;
    }

    public static function classForKey(string $key): ?string
    {
        return TriggerEventKey::fromKey($key)?->eventClass();
    }

    /** @return list<array{key: string, label: string}> */
    public function listActions(): array
    {
        return array_map(static fn (ActionKey $key): array => [
            'key' => $key->value,
            'label' => $key->label(),
        ], ActionKey::cases());
    }

    /** @return list<array{key: string, label: string}> */
    public function listOperators(): array
    {
        return array_map(static fn (ConditionOperator $op): array => [
            'key' => $op->value,
            'label' => $op->label(),
        ], ConditionOperator::cases());
    }
}
