/**
 * AWS Polly Zod Schemas
 * Centralized schema definitions for AWS Polly parameters
 */

import { z } from "zod";
import { AWS_POLLY_DEFAULTS, AWS_POLLY_CONFIG } from "../constants/awsPolly";
import { speechMarkSchema } from "../models/speechMarks";

/**
 * Base AWS Polly voice schema
 */
export const awsPollyVoiceSchema = z.string().default(AWS_POLLY_DEFAULTS.VOICE_ID);

/**
 * Base AWS Polly engine schema
 */
export const awsPollyEngineSchema = z.string().default(AWS_POLLY_DEFAULTS.ENGINE);

/**
 * Base AWS Polly output format schema
 */
export const awsPollyOutputFormatSchema = z.enum(AWS_POLLY_CONFIG.SUPPORTED_FORMATS).default(AWS_POLLY_DEFAULTS.OUTPUT_FORMAT);

/**
 * Standard AWS Polly request schema
 */
export const awsPollyRequestSchema = z.object({
  text: z.string().min(1),
  voiceId: awsPollyVoiceSchema.optional(),
  engine: awsPollyEngineSchema.optional(),
  outputFormat: awsPollyOutputFormatSchema.optional(),
});

/**
 * AWS Polly synthesis input schema (for services)
 */
export const awsPollySynthesisInputSchema = z.object({
  text: z.string().min(1).describe("Text to synthesize"),
  voiceId: z.string().optional().default(AWS_POLLY_DEFAULTS.VOICE_ID).describe("AWS Polly voice ID"),
  engine: z.string().optional().default(AWS_POLLY_DEFAULTS.ENGINE).describe("AWS Polly engine"),
  outputFormat: z.string().optional().default(AWS_POLLY_DEFAULTS.OUTPUT_FORMAT).describe("Audio output format"),
});

/**
 * AWS Polly metadata schema
 */
export const awsPollyMetadataSchema = z.object({
  voiceId: z.string().describe("AWS Polly voice used"),
  engine: z.string().describe("AWS Polly engine used"),
  outputFormat: z.string().describe("Audio output format"),
  duration: z.number().optional().describe("Audio duration in seconds"),
  fileSize: z.number().optional().describe("Audio file size in bytes"),
});

// Speech marks schema is imported from models/speechMarks.ts to avoid duplication

/**
 * Speech synthesis response schema
 */
export const speechSynthesisResponseSchema = z.object({
  audioId: z.string().describe("Unique audio identifier"),
  audioUrl: z.string().describe("URL to the synthesized audio"),
  speechMarks: z.array(speechMarkSchema).optional().describe("Word-level timing data"),
  duration: z.number().describe("Audio duration in seconds"),
  wordCount: z.number().describe("Number of words synthesized"),
  metadata: awsPollyMetadataSchema,
});

/**
 * Reusable AWS Polly configuration object schema
 */
export const awsPollyConfigSchema = z.object({
  voiceId: awsPollyVoiceSchema,
  engine: awsPollyEngineSchema,
  outputFormat: awsPollyOutputFormatSchema,
  timeout: z.number().optional().default(60000),
  retries: z.number().optional().default(3),
}); 