export interface AgentStatus {
  id: string;
  name: string;
  status:
    | "running"
    | "active"
    | "paused"
    | "resting"
    | "stopped"
    | "error"
    | "danger"
    | "bankrupt";
  strategy: string;
  symbol: string;
  profitLoss: number;
  profitLossPercent: number;
  tradesCount: number;
  lastUpdated: string;
}

export interface TradeRecord {
  id: string;
  agentId: string;
  agentName: string;
  symbol: string;
  side: "buy" | "sell";
  quantity: number;
  price: number;
  total: number;
  timestamp: string;
  pnl?: number;
  pnlPercent?: number;
}

export interface Metrics {
  totalEquity: number;
  dailyPnl: number;
  dailyPnlPercent: number;
  totalTrades: number;
  winRate: number;
  activeAgents: number;
  totalAgents: number;
}

export interface EquityPoint {
  timestamp: string;
  equity: number;
}

export interface PnlDistribution {
  range: string;
  count: number;
}

/** Dashboard alert from backend (bankruptcy, large loss, cost overrun, etc.) */
export interface DashboardAlert {
  alert_id: string;
  alert_type: string;
  level: "info" | "warning" | "error" | "critical";
  agent_id?: string;
  title: string;
  message: string;
  details?: Record<string, unknown>;
  acknowledged?: boolean;
  created_at?: string;
}

// Trading related types
export interface Order {
  id: string;
  symbol: string;
  side: "buy" | "sell";
  type: "market" | "limit" | "stop" | "stop_limit";
  status:
    | "pending"
    | "open"
    | "filled"
    | "partially_filled"
    | "cancelled"
    | "rejected";
  quantity: number;
  filledQuantity: number;
  price?: number;
  stopPrice?: number;
  total?: number;
  timestamp: string;
  updatedAt?: string;
}

export interface Position {
  id: string;
  symbol: string;
  side: "long" | "short";
  quantity: number;
  entryPrice: number;
  markPrice: number;
  liquidationPrice?: number;
  margin: number;
  leverage: number;
  unrealizedPnl: number;
  unrealizedPnlPercent: number;
  realizedPnl: number;
  openedAt: string;
}

export interface Ticker {
  symbol: string;
  lastPrice: number;
  priceChange: number;
  priceChangePercent: number;
  high24h: number;
  low24h: number;
  volume24h: number;
  quoteVolume24h: number;
  bidPrice: number;
  askPrice: number;
  bidQty: number;
  askQty: number;
  timestamp: string;
}

export interface OrderBookEntry {
  price: number;
  quantity: number;
  total?: number;
}

export interface OrderBook {
  symbol: string;
  bids: OrderBookEntry[];
  asks: OrderBookEntry[];
  timestamp: string;
}

export interface Kline {
  timestamp: string;
  open: number;
  high: number;
  low: number;
  close: number;
  volume: number;
  quoteVolume: number;
}

export type TradingMode = "simulation" | "live";

// Trade type for recent trades
export interface Trade {
  id: string;
  symbol: string;
  side: "buy" | "sell";
  price: number;
  quantity: number;
  total: number;
  timestamp: string;
}

// Exchange configuration
export interface Exchange {
  id: string;
  name: string;
  type: "binance" | "okx" | "bybit" | "custom";
  apiKey: string;
  apiSecret?: string;
  passphrase?: string;
  testnet: boolean;
  enabled?: boolean;
  status: "connected" | "disconnected" | "error";
  lastTested?: string;
  createdAt: string;
  updatedAt: string;
}

export interface ExchangeCreateRequest {
  name: string;
  type: "binance" | "okx" | "bybit" | "custom";
  apiKey: string;
  apiSecret: string;
  passphrase?: string;
  testnet: boolean;
}

export interface ExchangeUpdateRequest {
  name?: string;
  apiKey?: string;
  apiSecret?: string;
  passphrase?: string;
  testnet?: boolean;
}
