// SSE 事件类型 — 按契约§2，11类，前端按 event_seq 去重
// 注意：BE 用 named SSE events，FE 必须用 addEventListener 而非 onmessage（见 lib/sse.ts）

export interface SseBaseEvent { event_seq: number; }

export interface TaskStartedEvent extends SseBaseEvent {
  type: 'task_started';
  data: { task_id: number; total_text: number; total_image: number };
}

export interface AnalyzeDoneEvent extends SseBaseEvent {
  type: 'analyze_done';
  data: { features: string[] };
}

export interface TextProgressEvent extends SseBaseEvent {
  type: 'text_progress';
  data: { done: number; total: number };
}

export interface TextCandidateEvent extends SseBaseEvent {
  type: 'text_candidate';
  data: {
    candidate_id: number;
    angle_label: string;
    content: string;
    score: number;  // SSE 推总分整数（0-100），完整五维分在 GET /tasks/{id} 返回
  };
}

export interface ImageProgressEvent extends SseBaseEvent {
  type: 'image_progress';
  data: { done: number; total: number };
}

export interface ImageCandidateEvent extends SseBaseEvent {
  type: 'image_candidate';
  data: { candidate_id: number; strategy: 'A' | 'B' | 'C'; url: string; role: string };
}

export interface FlywheelInjectedEvent extends SseBaseEvent {
  type: 'flywheel_injected';
  data: { recent_preference: string; reject_reasons: string[] };
}

export interface BatchFailedEvent extends SseBaseEvent {
  type: 'batch_failed';
  data: { batch: string; reason: string; retryable: boolean };  // batch = 图片角色名字符串
}

export interface TaskDoneEvent extends SseBaseEvent {
  type: 'task_done';
  data: { task_id: number; status: string };
}

export interface SseErrorEvent extends SseBaseEvent {
  type: 'error';
  data: { code: number; message: string };
}

export interface HeartbeatEvent extends SseBaseEvent {
  type: 'heartbeat';
  data: { ts: number };
}

export type SseEvent =
  | TaskStartedEvent | AnalyzeDoneEvent | TextProgressEvent | TextCandidateEvent
  | ImageProgressEvent | ImageCandidateEvent | FlywheelInjectedEvent | BatchFailedEvent
  | TaskDoneEvent | SseErrorEvent | HeartbeatEvent;

