/**
 * Platform PDF Tool Types
 *
 * Zod schemas and inferred types for PDF rendering platform tool.
 * Supports document rendering with theme overrides and storage configuration.
 */

import { z } from 'zod'
import { DocumentSchema } from '../../../../../business/pdf/types'

// =============================================================================
// INPUT SCHEMA
// =============================================================================

/**
 * Storage configuration for PDF output
 * Specifies where the rendered PDF should be stored
 */
export const StorageConfigSchema = z.object({
  bucket: z.string().describe('Storage bucket name (e.g., "acquisition", "org-files")'),
  path: z.string().describe('File path within org folder (e.g., "proposals/deal-123/proposal.pdf")')
})

/**
 * Theme override schema (partial)
 * Allows customizing colors, typography, and spacing for PDF rendering
 */
export const ThemeOverrideSchema = z
  .object({
    colors: z.record(z.string(), z.string()).optional().describe('Color overrides (e.g., { primary: "#1a73e8" })'),
    typography: z.record(z.string(), z.any()).optional().describe('Typography overrides'),
    spacing: z.record(z.string(), z.number()).optional().describe('Spacing overrides in points')
  })
  .optional()

/**
 * Input schema for PDF rendering tool
 *
 * Renders a document definition to PDF and stores it in the specified location.
 */
export const PdfRenderInputSchema = z.object({
  document: DocumentSchema.describe('Document definition with pages, sections, and content blocks'),
  theme: ThemeOverrideSchema.describe('Optional theme customization'),
  storage: StorageConfigSchema.describe('Where to store the rendered PDF')
})

export type PdfRenderInput = z.infer<typeof PdfRenderInputSchema>

// =============================================================================
// OUTPUT SCHEMA
// =============================================================================

/**
 * Output schema for PDF render result
 * Returns the URL to the rendered PDF and file metadata
 */
export const PdfRenderOutputSchema = z.object({
  success: z.boolean().describe('Whether the PDF was rendered and stored successfully'),
  pdfUrl: z.string().describe('Signed URL to access the rendered PDF'),
  size: z.number().describe('File size in bytes')
})

export type PdfRenderOutput = z.infer<typeof PdfRenderOutputSchema>

// =============================================================================
// TOOL CONFIGURATION
// =============================================================================

/**
 * Configuration for creating a PDF render tool
 */
export interface PdfToolConfig {
  /** Unique name for the tool */
  name: string
  /** Description of what the tool does (shown to LLM) */
  description: string
}
