import { z } from 'zod';

export const ServiceSchema = z.object({
  id: z.string(),
  name: z.string(),
  scriptPath: z.string(),
  healthUrl: z.string().url(),
  repoPath: z.string(),
  status: z.enum(['up', 'down', 'degraded']),
  version: z.string(),
  lastDeployedAt: z.string().optional(),
  lastHealthCheckAt: z.string().optional(),
  productId: z.string(),
});

export type Service = z.infer<typeof ServiceSchema>;

export const CreateServiceSchema = ServiceSchema.partial({
  id: true,
  status: true,
  version: true,
  lastDeployedAt: true,
  lastHealthCheckAt: true,
});

export type CreateService = z.infer<typeof CreateServiceSchema>;

export const UpdateServiceSchema = ServiceSchema.partial({
  id: true,
  productId: true,
}).strict();

export type UpdateService = z.infer<typeof UpdateServiceSchema>;

export const ServiceParamsSchema = z.object({
  id: z.string().min(1, 'Service ID is required'),
});

export type ServiceParams = z.infer<typeof ServiceParamsSchema>;
