export interface Company {
  symbol: string;
  name: string;
  price: number;
  change: number;
  changePercent: number;
  marketCap: number;
  volume?: number;
  volumeLabel?: string;
  pe?: number;
  eps?: number;
  high52Week?: number;
  low52Week?: number;
  profile?: CompanyProfile;
  priceChart?: CompanyPricePoint[];
  priceChartRanges?: Partial<Record<CompanyPriceChartRange, CompanyPricePoint[]>>;
}

export type CompanyPriceChartRange =
  | '1D'
  | '5D'
  | '1M'
  | '6M'
  | 'YTD'
  | '1Y'
  | '5Y'
  | 'MAX';

export interface CompanyProfile {
  description?: string;
  wikiUrl?: string;
  ceo?: string;
  headquarters?: string;
  employees?: number;
  founded?: number;
  sector?: string;
  website?: string;
}

export interface CompanyPricePoint {
  label: string;
  price: number;
  volume?: number;
  timestamp?: string;
}

export interface Holding {
  symbol: string;
  name: string;
  quantity: number;
  avgCost: number;
  currentPrice: number;
  currentValue: number;
  gainLoss: number;
  gainLossPercent: number;
  costBasis?: number;
  unrealizedGain?: number;
  latestTradeAt?: string;
}

export interface Portfolio {
  holdings: Holding[];
  totalValue: number;
  dayChange: number;
  dayChangePercent: number;
  totalGain: number;
  totalGainPercent: number;
  cashBalance?: number;
  investedCostBasis?: number;
  realizedGain?: number;
  unrealizedGain?: number;
  holdingsCount?: number;
  stalePricingSymbols?: string[];
}

export interface StockAnalysis {
  symbol: string;
  summary: string;
  sentiment: 'bullish' | 'bearish' | 'neutral';
  keyPoints: string[];
  risks: string[];
  opportunities: string[];
  recommendation: 'buy' | 'sell' | 'hold';
  targetPrice?: number;
}

export interface MockFinancialData {
  companies: Company[];
  portfolio: Portfolio;
  analyses: Record<string, StockAnalysis>;
}

export type Frequency = 'annual' | 'quarterly';

export interface FilingRef {
  accessionNumber: string;
  filingDate: string;
  reportDate?: string;
  form: string;
  primaryDocument?: string;
}

export interface SourceStatus {
  companyfactsUsed: boolean;
  latestXbrlParsed: boolean;
  degradedReason?: string;
}

export interface StatementPeriod {
  label: string;
  fiscalYear?: string;
  fiscalPeriod?: string;
  periodStart?: string;
  periodEnd: string;
  filedDate: string;
  form: string;
  revenue?: number;
  grossProfit?: number;
  operatingIncome?: number;
  netIncome?: number;
  dilutedEps?: number;
  cashAndEquivalents?: number;
  totalAssets?: number;
  totalLiabilities?: number;
  totalEquity?: number;
  sharesOutstanding?: number;
}

export interface CashFlowPeriod {
  label: string;
  fiscalYear?: string;
  fiscalPeriod?: string;
  periodStart?: string;
  periodEnd: string;
  filedDate: string;
  form: string;
  operatingCashFlow?: number;
  investingCashFlow?: number;
  financingCashFlow?: number;
  capex?: number;
  freeCashFlow?: number;
  endingCash?: number;
}

export interface DividendEvent {
  endDate: string;
  filedDate: string;
  form: string;
  frequencyGuess: string;
  dividendPerShare?: number;
  totalCashDividends?: number;
}

export interface EarningsPeriod {
  label: string;
  fiscalYear?: string;
  fiscalPeriod?: string;
  periodStart?: string;
  periodEnd: string;
  filedDate: string;
  form: string;
  revenue?: number;
  netIncome?: number;
  basicEps?: number;
  dilutedEps?: number;
  dilutedWeightedAverageShares?: number;
  revenueYoyChangePercent?: number;
  dilutedEpsYoyChangePercent?: number;
}

export interface FinancialsPanelData {
  symbol: string;
  companyName: string;
  cik: string;
  frequency: Frequency;
  periods: StatementPeriod[];
  latestFiling?: FilingRef;
  sourceStatus: SourceStatus;
}

export interface CashFlowPanelData {
  symbol: string;
  companyName: string;
  cik: string;
  frequency: Frequency;
  periods: CashFlowPeriod[];
  latestFiling?: FilingRef;
  sourceStatus: SourceStatus;
}

export interface DividendsPanelData {
  symbol: string;
  companyName: string;
  cik: string;
  ttmDividendsPerShare?: number;
  ttmCommonDividendsPaid?: number;
  latestEvent?: DividendEvent;
  events: DividendEvent[];
  latestFiling?: FilingRef;
  sourceStatus: SourceStatus;
}

export interface EarningsPanelData {
  symbol: string;
  companyName: string;
  cik: string;
  frequency: Frequency;
  periods: EarningsPeriod[];
  latestFiling?: FilingRef;
  sourceStatus: SourceStatus;
}
