import type { RequestFormat } from "../../../proxy/schemas";
import type { AnatomySegment } from "../anatomy/types";

export type RequestAnalysis = {
  parsed: unknown | null;
  comparisonValue: unknown;
  messageCount: number | null;
  toolCount: number | null;
};

export type ResponseAnalysis = {
  parsed: unknown | null;
  toolNames: string[] | null;
};

export type LogFormatAdapter = {
  readonly format: RequestFormat;
  analyzeRequest(rawBody: string | null): RequestAnalysis;
  analyzeResponse(responseText: string | null): ResponseAnalysis;
  /**
   * Derive the ordered list of segments shown in the Anatomy tab for a
   * parsed request body. Returns `null` when the body is `null` or fails
   * the format's schema (e.g. unknown format).
   */
  anatomySegments(parsed: unknown): AnatomySegment[] | null;
};

export function emptyRequestAnalysis(rawBody: string | null): RequestAnalysis {
  return {
    parsed: null,
    comparisonValue: rawBody,
    messageCount: null,
    toolCount: null,
  };
}

export const EMPTY_RESPONSE_ANALYSIS: ResponseAnalysis = {
  parsed: null,
  toolNames: null,
};
