<?php

namespace GriffinForms\Includes\Ai;

class SurfaceRouter
{
    protected AssistFailureFramework $failure_framework;

    public function __construct()
    {
        $this->failure_framework = new AssistFailureFramework();
    }

    public function route(int $form_id, string $prompt, array $selected_context = [], array $request_context = []): array
    {
        $surface = sanitize_key((string) ($request_context['surface'] ?? 'form_builder'));
        if ($surface === '') {
            $surface = 'form_builder';
        }

        return match ($surface) {
            'form_builder' => (new BuilderAssistRouter())->execute($form_id, $prompt, $selected_context, $request_context),
            'submissions'  => $this->failure_framework->build('unsupported_surface', 501, ['surface' => $surface]),
            'messages'     => $this->failure_framework->build('unsupported_surface', 501, ['surface' => $surface]),
            default        => $this->failure_framework->build('unsupported_surface', 501, ['surface' => $surface]),
        };
    }
}
