export type WorldDefaultPayload = {
  worldId?: string;
  world?: {
    id?: string;
  };
};

export type LaunchState = "ready" | "opening" | "opened" | "blocked" | "error";
export type BoardTab = "news" | "requests";
export type LauncherWindowMode = "public" | "admin";
export type LauncherRequestStatus = "pending" | "active" | "implemented";
export type AdminDetailTab = "routing" | "analysis";

export type LauncherRequestAnalysisRouting = {
  summary?: string;
  ambiguity?: "low" | "medium" | "high";
  matchedTerms?: string[];
  suggestedTags?: string[];
  suggestedSystems?: string[];
  suggestedModules?: string[];
  rationale?: string;
  possibleDirections?: string[];
  kbSections?: string[];
};

export type LauncherRequestAnalysisItem = {
  title?: string;
  primaryCategory?: string;
  tags?: string[];
  statusRecommendation?: string;
  parsedInterpretation?: string;
  implementationApproach?: string;
  affectedSystems?: string[];
  affectedFiles?: string[];
  problemType?: string;
  rawExcerpt?: string;
  confidence?: number | null;
  reviewRationale?: string;
  reviewOptions?: string[];
  notes?: string;
};

export type LauncherRequest = {
  id: string;
  sourceSubmissionId?: string;
  title: string;
  status: LauncherRequestStatus;
  category: string;
  tags: string[];
  sourceText: string;
  summary: string;
  implementationNotes: string;
  analysis?: {
    state?: "unprocessed" | "processing" | "processed" | "needs_review" | "error";
    confidence?: number | null;
    model?: string;
    createdAt?: string;
    updatedAt?: string;
    error?: string;
    submissionId?: string;
    sourceTextSnapshot?: string;
    routing?: LauncherRequestAnalysisRouting;
    itemCount?: number;
    items?: LauncherRequestAnalysisItem[];
  };
  createdAt: string;
  updatedAt: string;
};

export type LauncherRequestsPayload = {
  requests?: LauncherRequest[];
};

export type RecentSaveEvent = {
  at?: string;
  type?: string;
  requestId?: string;
  textPreview?: string;
  status?: string;
  category?: string;
  itemCount?: number;
  model?: string;
  reason?: string;
  provider?: string;
  pid?: number;
  code?: number | null;
  signal?: string;
  error?: string;
};

export type RecentSaveEventsPayload = {
  saves?: RecentSaveEvent[];
};

export type ProcessPendingPayload = {
  ok?: boolean;
  launched?: boolean;
  reason?: string;
  autorunEnabled?: boolean;
  configured?: boolean;
  queuedPendingCount?: number;
  pid?: number;
};

export type RequeueAnalysisPayload = {
  ok?: boolean;
  launched?: boolean;
  reason?: string;
  request?: LauncherRequest;
  requests?: LauncherRequest[];
  requestId?: string;
  queuedPendingCount?: number;
  pid?: number;
};

export type LauncherRequestMetaPayload = {
  allowedTags?: string[];
};

export type AdminAuthPayload = {
  ok?: boolean;
  accessGranted?: boolean;
  adminConfigured?: boolean;
  error?: string;
};

export const DEFAULT_EDITOR_WORLD_ID_FALLBACK = "overworld";
