export type MessageType = "user" | "bot" | "system";
export type MessageStatus = "sent" | "delivered" | "read" | "failed";
export type SessionStatus = "active" | "closed";

export interface ChatMessage {
  id: string;
  content: string;
  type: MessageType;
  status: MessageStatus;
  createdAt: string;
  responseToId?: string | null;
  metadata?: Record<string, unknown>;
  tokensUsed?: number;
}

export interface ChatSession {
  id: string;
  status: SessionStatus;
  createdAt: string;
  lastMessageAt: string;
  messages: ChatMessage[];
}

export interface SessionCreatedResponse {
  status: "success";
  data: ChatSession;
  timestamp: string;
}

export interface ChatJoinedResponse {
  status: "success";
  data: ChatSession;
  timestamp: string;
}

export interface MessageReceivedResponse {
  status: "success";
  data: ChatMessage;
  timestamp: string;
}

export interface BotResponse {
  status: "success";
  data: {
    id: string;
    content: string;
    type: "bot";
    status: MessageStatus;
    createdAt: string;
    responseToId: string;
    metadata?: {
      confidence?: number;
      sources?: unknown[];
      llmContext?: Record<string, unknown>;
    };
    tokensUsed: number;
  };
  timestamp: string;
}

export interface BotResponseStart {
  status: "success";
  data: {
    userMessageId: string;
  };
  timestamp: string;
}

export interface BotResponseChunk {
  status: "success";
  data: {
    chunk: string;
    userMessageId: string;
  };
  timestamp: string;
}

export interface BotResponseEnd {
  status: "success";
  data: {
    userMessageId: string;
    fullResponse: string;
  };
  timestamp: string;
}

export interface ErrorResponse {
  status: "error";
  message: string;
  timestamp: string;
}

export interface AuthenticatedResponse {
  message: "authenticated";
  userId?: string;
  timestamp: string;
}

export interface UnauthorizedResponse {
  message: string;
  timestamp: string;
}

export interface SendMessagePayload {
  content: string;
  sessionId: string;
  responseToId?: string | null;
  metadata?: Record<string, unknown>;
}

export type ConnectionStatus =
  | "disconnected"
  | "connecting"
  | "connected"
  | "reconnecting"
  | "error";
