/**
 * Platform Storage Tool Types
 * Zod schemas and TypeScript types for storage platform tools
 */

import { z } from 'zod'

// =============================================================================
// Input Schemas
// =============================================================================

/**
 * Schema for storage upload tool input
 */
export const StorageUploadInputSchema = z.object({
  bucket: z.string().describe('Storage bucket name (e.g., "acquisition", "org-files", "assets")'),
  path: z.string().describe('File path within org folder (e.g., "proposals/deal-123/proposal.pdf")'),
  content: z.string().describe('Base64 encoded file content'),
  contentType: z.string().describe('MIME type (e.g., "application/pdf", "image/png")'),
  upsert: z.boolean().optional().describe('Overwrite if file exists (default: false)')
})

/**
 * Schema for storage signed URL tool input
 */
export const StorageSignedUrlInputSchema = z.object({
  bucket: z.string().describe('Storage bucket name'),
  path: z.string().describe('File path within org folder'),
  expiresIn: z.number().default(86400).describe('URL expiration in seconds (default: 86400 = 24 hours)')
})

/**
 * Schema for storage download tool input
 */
export const StorageDownloadInputSchema = z.object({
  bucket: z.string().describe('Storage bucket name'),
  path: z.string().describe('File path within org folder')
})

/**
 * Schema for storage delete tool input
 */
export const StorageDeleteInputSchema = z.object({
  bucket: z.string().describe('Storage bucket name'),
  path: z.string().describe('File path within org folder')
})

/**
 * Schema for storage list tool input
 */
export const StorageListInputSchema = z.object({
  bucket: z.string().describe('Storage bucket name'),
  prefix: z.string().optional().describe('Path prefix to filter files (e.g., "proposals/")')
})

// =============================================================================
// Output Schemas
// =============================================================================

/**
 * Schema for storage upload tool output
 */
export const StorageUploadOutputSchema = z.object({
  success: z.boolean(),
  path: z.string().describe('Relative file path'),
  fullPath: z.string().describe('Full path including org prefix')
})

/**
 * Schema for storage signed URL tool output
 */
export const StorageSignedUrlOutputSchema = z.object({
  success: z.boolean(),
  signedUrl: z.string().describe('Temporary signed URL for file access'),
  expiresAt: z.string().describe('ISO date when URL expires')
})

/**
 * Schema for storage download tool output
 */
export const StorageDownloadOutputSchema = z.object({
  success: z.boolean(),
  content: z.string().describe('Base64 encoded file content'),
  contentType: z.string().optional().describe('MIME type if known')
})

/**
 * Schema for storage delete tool output
 */
export const StorageDeleteOutputSchema = z.object({
  success: z.boolean()
})

/**
 * Schema for storage list tool output
 */
export const StorageListOutputSchema = z.object({
  success: z.boolean(),
  files: z.array(z.string()).describe('List of file names')
})

// =============================================================================
// TypeScript Types
// =============================================================================

export type StorageUploadInput = z.infer<typeof StorageUploadInputSchema>
export type StorageSignedUrlInput = z.infer<typeof StorageSignedUrlInputSchema>
export type StorageDownloadInput = z.infer<typeof StorageDownloadInputSchema>
export type StorageDeleteInput = z.infer<typeof StorageDeleteInputSchema>
export type StorageListInput = z.infer<typeof StorageListInputSchema>

export type StorageUploadOutput = z.infer<typeof StorageUploadOutputSchema>
export type StorageSignedUrlOutput = z.infer<typeof StorageSignedUrlOutputSchema>
export type StorageDownloadOutput = z.infer<typeof StorageDownloadOutputSchema>
export type StorageDeleteOutput = z.infer<typeof StorageDeleteOutputSchema>
export type StorageListOutput = z.infer<typeof StorageListOutputSchema>

// =============================================================================
// Tool Configuration Types
// =============================================================================

/**
 * Configuration for storage tool factories
 */
export interface StorageToolConfig {
  name: string
  description: string
}
