export type NewsSentiment = "BULL" | "BEAR" | "NEUTRAL";

export type HighlightReason =
  | "breaking_keyword"
  | "macro_event"
  | "strong_sentiment"
  | "ticker_detected"
  | "recent_high_value";

export interface NewsArticle {
  id: string;
  sourceId: string;
  source: string;
  headline: string;
  summary: string;
  url?: string;
  canonicalUrl?: string;
  publishedAt: string;
  publishedTs: number;
  fetchedAt: string;
  sentiment: NewsSentiment;
  sentimentScore: number;
  highlightReason?: HighlightReason;
  tickers: string[];
  isRead: boolean;
  isSaved: boolean;
}

export interface QueryNewsFeedRequest {
  ticker?: string;
  search?: string;
  onlyHighlighted?: boolean;
  onlySaved?: boolean;
  onlyUnread?: boolean;
  limit?: number;
  offset?: number;
}

export interface NewsSourceConfig {
  id: string;
  name: string;
  url: string;
  refreshMinutes: number;
}

export interface NewsSourceStatus {
  id: string;
  name: string;
  url: string;
  refreshMinutes: number;
  lastCheckedAt?: string;
  lastSuccessAt?: string;
  lastError?: string;
  failureCount: number;
}

export interface QueryNewsFeedResponse {
  articles: NewsArticle[];
  total: number;
  lastSyncedAt?: string;
  sources: NewsSourceStatus[];
}

export interface RefreshNewsFeedRequest {
  force?: boolean;
}

export interface RefreshNewsFeedResult {
  feedsChecked: number;
  feedsSucceeded: number;
  feedsFailed: number;
  newArticles: number;
  updatedArticles: number;
  unchangedArticles: number;
  finishedAt: string;
}

export interface UpdateNewsArticleStateRequest {
  articleId: string;
  isRead?: boolean;
  isSaved?: boolean;
}

export interface SaveNewsFeedConfigRequest {
  feeds: NewsSourceConfig[];
}
