export type CareWayEventName =
  | "subscription"
  | "progress"
  | "sources"
  | "heartbeat"
  | "completed"
  | "error"
  | "done";

export interface CareWayEvent<T = unknown> {
  event: CareWayEventName | string;
  data: T;
}

export interface CareWayOptions {
  apiKey: string;
  baseUrl?: string;
  timeoutMs?: number;
}

export class CareWayError extends Error {
  code: string;
  status: number;
  constructor(code: string, message: string, status?: number);
}

export class CareWay {
  constructor(options: CareWayOptions);
  subscription(): Promise<Record<string, unknown>>;
  listChats(): Promise<Array<Record<string, unknown>>>;
  createChat(options?: { title?: string | null }): Promise<Record<string, unknown>>;
  getChat(chatId: string): Promise<Record<string, unknown>>;
  deleteChat(chatId: string): Promise<boolean>;
  sendMessage(
    chatId: string,
    options: { text: string; idempotencyKey?: string }
  ): Promise<Record<string, unknown>>;
  streamMessage(
    chatId: string,
    options: { text: string; idempotencyKey?: string }
  ): AsyncGenerator<CareWayEvent>;
  feedback(
    chatId: string,
    messageId: string,
    options: { correct: boolean; actualCause?: string | null }
  ): Promise<Record<string, unknown>>;
}
