import { requestFormatForPath } from "../../../proxy/formats";
import type { CapturedLog, RequestFormat } from "../../../proxy/schemas";
import { anthropicLogFormatAdapter } from "./anthropic";
import { openAILogFormatAdapter } from "./openai";
import type { LogFormatAdapter } from "./types";
import { unknownLogFormatAdapter } from "./unknown";

const ADAPTERS: Record<RequestFormat, LogFormatAdapter> = {
  anthropic: anthropicLogFormatAdapter,
  openai: openAILogFormatAdapter,
  unknown: unknownLogFormatAdapter,
};

export function getLogFormatAdapter(format: RequestFormat): LogFormatAdapter {
  return ADAPTERS[format];
}

export function resolveLogFormat(log: Pick<CapturedLog, "path" | "apiFormat">): RequestFormat {
  const pathFormat = requestFormatForPath(log.path);
  return pathFormat === "unknown" ? log.apiFormat : pathFormat;
}

export type { LogFormatAdapter, RequestAnalysis, ResponseAnalysis } from "./types";
