/**
 * Asset Schema - Zod validation for asset forms
 */

import { z } from 'zod';

export const assetSchema = z.object({
  project: z.unknown().optional().nullable(),
  name: z.string().min(1, 'Name is required').max(255, 'Name too long'),
  asset_type: z.enum(['image', 'video', 'audio', 'file']),
  type: z
    .enum([
      'general',
      'icon',
      'background_image',
      'audio',
      'video',
      'transition',
      'logo',
      'favicon',
      'document',
    ])
    .default('general'),
  cdn_url: z.string().url('Invalid URL').optional().or(z.literal('')),
  storage_key: z
    .string()
    .max(500, 'Storage key too long')
    .optional()
    .or(z.literal('')),
  mime_type: z
    .string()
    .max(100, 'MIME type too long')
    .optional()
    .or(z.literal('')),
  size_mb: z.coerce
    .number()
    .min(0, 'Size cannot be negative')
    .optional()
    .or(z.literal('')),
  width_px: z.coerce
    .number()
    .int()
    .min(0, 'Width cannot be negative')
    .optional()
    .or(z.literal('')),
  height_px: z.coerce
    .number()
    .int()
    .min(0, 'Height cannot be negative')
    .optional()
    .or(z.literal('')),
  duration_sec: z.coerce
    .number()
    .min(0, 'Duration cannot be negative')
    .optional()
    .or(z.literal('')),
  checksum: z
    .string()
    .max(255, 'Checksum too long')
    .optional()
    .or(z.literal('')),
  is_public: z.boolean().default(false),
  is_deleted: z.boolean().default(false),
  deleted_at_time: z.date().optional().nullable(),
});

export type AssetFormData = z.infer<typeof assetSchema>;

export const assetInitialValues: AssetFormData = {
  project: null,
  name: '',
  asset_type: 'image',
  type: 'general',
  cdn_url: '',
  storage_key: '',
  mime_type: '',
  size_mb: '',
  width_px: '',
  height_px: '',
  duration_sec: '',
  checksum: '',
  is_public: false,
  is_deleted: false,
  deleted_at_time: null,
};
