import { z } from 'zod';

export const listFilesQuerySchema = z.object({
  path: z.string().default('.'),
});

export const fileEntrySchema = z.object({
  name: z.string(),
  path: z.string(),
  type: z.enum(['file', 'directory']),
  size: z.number().int().nonnegative().optional(),
  modifiedAt: z.string().datetime().optional(),
});

export const fileListResponseSchema = z.object({
  path: z.string(),
  entries: z.array(fileEntrySchema),
});

export const fileContentSchema = z.object({
  path: z.string(),
  content: z.string(),
  encoding: z.enum(['utf-8', 'base64']).default('utf-8'),
});

export const readFileContentQuerySchema = z.object({
  path: z.string().min(1),
});

export const updateFileContentSchema = z.object({
  path: z.string().min(1),
  content: z.string(),
  encoding: z.enum(['utf-8', 'base64']).default('utf-8'),
});

export type ListFilesQuery = z.infer<typeof listFilesQuerySchema>;
export type FileEntry = z.infer<typeof fileEntrySchema>;
export type FileListResponse = z.infer<typeof fileListResponseSchema>;
export type FileContent = z.infer<typeof fileContentSchema>;
export type ReadFileContentQuery = z.infer<typeof readFileContentQuerySchema>;
export type UpdateFileContent = z.infer<typeof updateFileContentSchema>;
