import { z } from 'zod';

const messageSchema = z.object({
  role: z.enum(['user', 'assistant', 'system']),
  content: z.string(),
  timestamp: z.string().optional(),
});

export const createConversationSchema = z.object({
  branch_id: z.string().uuid().optional(),
  customer_id: z.string().uuid().optional(),
  customer_name: z.string().optional(),
  channel: z.enum(['chat', 'voice', 'whatsapp', 'email', 'sms']).optional(),
  topic: z.string().optional(),
  messages: z.array(messageSchema).optional(),
});

export const updateConversationSchema = z.object({
  status: z.enum(['ai', 'human', 'resolved']).optional(),
  assigned_agent: z.string().optional(),
  messages: z.array(messageSchema).optional(),
  unread_count: z.number().int().nonnegative().optional(),
  topic: z.string().optional(),
});

export const addMessageSchema = z.object({
  role: z.enum(['user', 'assistant', 'system']),
  content: z.string().min(1, 'Message content is required'),
});

export type CreateConversationInput = z.infer<typeof createConversationSchema>;
export type UpdateConversationInput = z.infer<typeof updateConversationSchema>;
export type AddMessageInput = z.infer<typeof addMessageSchema>;
