import {
  CreateEventDTO,
  UpdateEventDTO,
  RecurringDeleteMode,
} from "./CalendarEvent";

export type MessageSender = "user" | "assistant";

export type EventAction = "create" | "update" | "delete";

export type RespondedAction = "confirm" | "reject";

export interface ConflictingEvent {
  title: string;
  startTime: Date;
  endTime: Date;
}

export interface ProposedEventChange {
  id: string; // Unique ID for each proposal
  action: EventAction;
  eventId?: string; // Required for update/delete
  event?: CreateEventDTO; // Required for create
  updates?: UpdateEventDTO; // Required for update
  respondedAction?: RespondedAction; // User's response to this specific proposal
  deleteMode?: RecurringDeleteMode; // For recurring event deletion
  occurrenceDate?: string; // ISO date string of specific occurrence for single/future delete
  conflictingEvents?: ConflictingEvent[]; // Overlapping events for conflict warnings
}

export interface ChatMessage {
  id: string;
  conversationId: string;
  sender: MessageSender;
  content: string;
  proposedChanges?: ProposedEventChange[]; // Array of event proposals
  createdAt?: Date;
}

export interface Conversation {
  id: string;
  userId: string;
  createdAt?: Date;
  updatedAt?: Date;
}

export interface SendMessageDTO {
  conversationId?: string;
  content: string;
}

export interface CreateMessageDTO {
  sender: MessageSender;
  content: string;
  proposedChanges?: ProposedEventChange[];
}

export interface GetMessagesOptions {
  before?: string; // Message ID - load messages before this one
  limit?: number; // Default: 20
}

export interface UpdateMessageDTO {
  proposalId?: string; // Identifies which proposal to update
  respondedAction?: RespondedAction;
}

export interface ChatResponse {
  message: ChatMessage;
  conversationId: string;
}

export interface ConversationSummary {
  id: string;
  lastMessage?: ChatMessage;
  createdAt?: Date;
}
