import type {
  CopyOptimizationRequest,
  CopyOptimizationResult,
} from "../domain/types";
import { copyOptimizationResultSchema } from "../domain/validation";
import { generateValidatedJson, type GenerateInput } from "../llm/client";
import {
  RENWEI_COPY_OPTIMIZER_SYSTEM_PROMPT,
  buildRenweiCopyOptimizationPrompt,
} from "../llm/prompts";

export async function optimizeRenweiCopy(
  input: CopyOptimizationRequest,
  options: { onAuditSummary?: GenerateInput["onAuditSummary"] } = {},
): Promise<CopyOptimizationResult> {
  return generateValidatedJson({
    schema: copyOptimizationResultSchema,
    system: RENWEI_COPY_OPTIMIZER_SYSTEM_PROMPT,
    prompt: buildRenweiCopyOptimizationPrompt(input),
    temperature: 0.2,
    task: "renwei_copy_optimizer",
    onAuditSummary: options.onAuditSummary,
  });
}
