import { z } from 'zod'

export const updateStrategySchema = z.enum(['optional', 'forced'])
export const updateTypeSchema = z.enum(['full', 'patch'])
export const updateMethodSchema = z.enum(['auto', 'manual'])
export const publishStatusSchema = z.enum(['draft', 'published', 'deprecated', 'superseded'])

export const versionSchema = z.object({
  id: z.number(),
  application_id: z.number(),
  application_name: z.string(),
  version: z.string(),
  description: z.string(),
  file_path: z.string(),
  file_size: z.number(),
  file_hash: z.string().optional(),
  update_strategy: updateStrategySchema,
  update_type: updateTypeSchema,
  update_method: updateMethodSchema,
  status: z.string(), // 兼容旧字段
  publish_status: publishStatusSchema,
  superseded_by: z.number().nullable().optional(),
  published_at: z.string().nullable().optional(),
  deprecated_at: z.string().nullable().optional(),
  changelog: z.string(),
  delta_package_path: z.string().optional(),
  delta_package_size: z.number().optional(),
  full_package_path: z.string().optional(),
  full_package_size: z.number().optional(),
  created_at: z.string(),
  updated_at: z.string(),
})

export type Version = z.infer<typeof versionSchema>
