import { Company, NewsItem, Portfolio, SerializedNewsItem, StockAnalysis } from './financial';
import { ProviderMode, TaskProfile } from './agentSettings';

export type PanelPayload =
  | { type: 'company'; data: Company }
  | { type: 'portfolio'; data: Portfolio }
  | { type: 'news'; data: NewsItem[]; ticker?: string }
  | { type: 'analysis'; data: StockAnalysis };

export type TransportPanelPayload =
  | { type: 'company'; data: Company }
  | { type: 'portfolio'; data: Portfolio }
  | { type: 'news'; data: SerializedNewsItem[]; ticker?: string }
  | { type: 'analysis'; data: StockAnalysis };

export type TerminalCommandResponse =
  | { kind: 'text'; content: string }
  | { kind: 'panel'; panel: TransportPanelPayload };

export type ResolvedTerminalCommandResponse =
  | { kind: 'text'; content: string }
  | { kind: 'panel'; panel: PanelPayload };

export interface ExecuteTerminalCommandRequest {
  workspaceId: string;
  input: string;
}

export interface StartChatStreamRequest {
  workspaceId: string;
  sessionId?: string;
  prompt: string;
  agentProfile?: TaskProfile;
  modelOverride?: string;
  providerOverride?: ProviderMode;
}

export interface ChatStreamStart {
  requestId: string;
  sessionId: string;
}

export interface AgentDeltaEvent {
  workspaceId: string;
  requestId: string;
  sessionId: string;
  delta: string;
}

export interface AgentResultEvent {
  workspaceId: string;
  requestId: string;
  sessionId: string;
  reply: string;
}

export interface AgentErrorEvent {
  workspaceId: string;
  requestId: string;
  sessionId: string;
  message: string;
}

export interface TerminalEntry {
  id: string;
  type: 'command' | 'response' | 'system' | 'error' | 'panel';
  content: string | PanelPayload;
  timestamp?: Date;
}

export interface CommandSuggestion {
  command: string;
  description: string;
  category: 'search' | 'portfolio' | 'news' | 'analysis' | 'system';
}

export interface TerminalState {
  history: TerminalEntry[];
  currentIndex: number;
  isProcessing: boolean;
}
