import type { ToolEffect } from "@best-agent/protocol";
import type { ConversationMessage, ProviderToolOption } from "../../provider/provider-core.js";
import { validateProviderFinalAnswer } from "./provider-final-validator.js";

export function validateProviderResponseFinalAnswer(input: {
  availableTools: readonly ProviderToolOption[];
  messages: ConversationMessage[];
  objective?: string;
  text: string;
}): ReturnType<typeof validateProviderFinalAnswer> {
  return validateProviderFinalAnswer({
    messages: input.messages,
    objective: input.objective,
    text: input.text,
    toolEffects: providerToolEffectMap(input.availableTools),
  });
}

function providerToolEffectMap(
  tools: readonly ProviderToolOption[],
): ReadonlyMap<string, ToolEffect> {
  const effects = new Map<string, ToolEffect>();
  for (const tool of tools) {
    effects.set(tool.name, tool.effect);
  }
  return effects;
}
