import { z } from 'zod';

export const createSharedViewSchema = z.object({
  name: z.string().min(1).max(100),
  description: z.string().optional(),
  includedLayerTypes: z.array(z.string()),
  shareScope: z.enum(['MEMBERS', 'PUBLIC']),
});

export const updateSharedViewSchema = z.object({
  name: z.string().min(1).max(100).optional(),
  description: z.string().nullable().optional(),
  includedLayerTypes: z.array(z.string()).optional(),
  shareScope: z.enum(['MEMBERS', 'PUBLIC']).optional(),
});

export const inviteMembersSchema = z.object({
  userIds: z.array(z.string().min(1)).min(1).max(20),
});

export const respondToInviteSchema = z.object({
  status: z.enum(['ACCEPTED', 'DECLINED']),
});

export const createCommentSchema = z.object({
  date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'Date must be YYYY-MM-DD'),
  itemId: z.string().optional(),
  content: z.string().min(1).max(500),
});

export const createReactionSchema = z.object({
  itemId: z.string().min(1),
  emoji: z.string().min(1).max(4),
});

export const shareItemSchema = z.object({
  friendIds: z.array(z.string().min(1)).min(1).max(10),
  message: z.string().max(200).optional(),
});

export const availabilityQuerySchema = z.object({
  start: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'start must be YYYY-MM-DD'),
  end: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'end must be YYYY-MM-DD'),
  dayStart: z.string().regex(/^\d{2}:\d{2}$/).default('09:00'),
  dayEnd: z.string().regex(/^\d{2}:\d{2}$/).default('17:00'),
  slotDuration: z.coerce.number().refine(v => [15, 30, 60].includes(v)).default(30),
});

export const dateRangeQuerySchema = z.object({
  startDate: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'startDate must be YYYY-MM-DD'),
  endDate: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'endDate must be YYYY-MM-DD'),
});

export type CreateSharedViewInput = z.infer<typeof createSharedViewSchema>;
export type UpdateSharedViewInput = z.infer<typeof updateSharedViewSchema>;
export type InviteMembersInput = z.infer<typeof inviteMembersSchema>;
export type RespondToInviteInput = z.infer<typeof respondToInviteSchema>;
export type CreateCommentInput = z.infer<typeof createCommentSchema>;
export type CreateReactionInput = z.infer<typeof createReactionSchema>;
export type ShareItemInput = z.infer<typeof shareItemSchema>;
export type AvailabilityQueryInput = z.infer<typeof availabilityQuerySchema>;
