/**
 * Blob storage types — Zod schemas for upload/download/list operations.
 */

import { z } from 'zod';
import { BLOB_CONTAINERS } from '../../lib/blob.js';

const containerNames = Object.values(BLOB_CONTAINERS) as [string, ...string[]];

export const GenerateSasSchema = z.object({
  container: z.enum(containerNames),
  blobName: z.string().min(1).max(1024),
  permissions: z.enum(['r', 'w', 'rw', 'rwc', 'rwd']).default('r'),
  expiresInMinutes: z.number().int().min(1).max(1440).default(60),
});

export const ListBlobsSchema = z.object({
  container: z.enum(containerNames),
  prefix: z.string().max(512).optional(),
  limit: z.coerce.number().int().min(1).max(500).default(100),
});

export const DeleteBlobSchema = z.object({
  container: z.enum(containerNames),
  blobName: z.string().min(1).max(1024),
});

export const BlobInfoQuerySchema = z.object({
  container: z.enum(containerNames),
  blobName: z.string().min(1).max(1024),
});

export const UploadMetadataSchema = z.object({
  container: z.enum(containerNames),
  blobName: z.string().min(1).max(1024),
  contentType: z.string().default('application/octet-stream'),
  metadata: z.record(z.string()).optional(),
});

export interface BlobInfo {
  name: string;
  container: string;
  contentType: string | undefined;
  size: number;
  lastModified: Date | undefined;
  url: string;
  metadata: Record<string, string>;
}

export type GenerateSasInput = z.infer<typeof GenerateSasSchema>;
export type ListBlobsInput = z.infer<typeof ListBlobsSchema>;
export type DeleteBlobInput = z.infer<typeof DeleteBlobSchema>;
export type BlobInfoQueryInput = z.infer<typeof BlobInfoQuerySchema>;
export type UploadMetadataInput = z.infer<typeof UploadMetadataSchema>;
