// ── Twitter Agent Types ──────────────────────────────────────

export type TweetContentType =
  | 'game_preview'
  | 'prop_pick'
  | 'line_alert'
  | 'hot_take'
  | 'recap'
  | 'blog_promo'
  | 'thread_hook'
  | 'thread_part'
  | 'video'
  | 'engagement_reply'
  | 'free_question'
  | 'weekly_recap'
  | 'event_driven'
  | 'performance_recap';

export type TweetStatus = 'pending' | 'media_generating' | 'posting' | 'posted' | 'failed';
export type MediaType = 'image' | 'video' | null;

export interface TweetContent {
  text: string;
  contentType: TweetContentType;
  league?: string;
  mediaType?: MediaType;
  imagePrompt?: string;
  inReplyTo?: string;
  threadParentId?: number;
  blogPostId?: number;
  gameKey?: string;         // Normalized event ID, e.g. "nba:celtics@lakers"
  pickDirection?: string;   // "home" | "away" | "over" | "under"
  isPickType?: boolean;
  enrichedData?: import('../seo/data-enrichment').EnrichedGameData;
  pickDetails?: PickDetails;
}

export interface PickDetails {
  gameKey: string;
  league: string;
  pickType: string;           // spread, moneyline, total, prop_over, prop_under
  selection: string;          // "Celtics -3.5", "Over 218.5", "Tatum Over 28.5 Pts"
  pickDirection: string;      // home, away, over, under
  lineValue?: number;
  oddsAmerican?: number;
  confidence?: string;
  edgePct?: number;
  shortReason: string;
  longReasonMd?: string;
  mathBreakdown?: Record<string, unknown>;
  gameDate?: string;
}

export interface TweetRow {
  id: number;
  tweet_id: string | null;
  content_type: string;
  tweet_text: string;
  league: string | null;
  media_type: string | null;
  media_task_id: string | null;
  media_url: string | null;
  twitter_media_id: string | null;
  thread_parent_id: number | null;
  in_reply_to: string | null;
  status: string;
  error: string | null;
  impressions: number;
  likes: number;
  retweets: number;
  replies: number;
  blog_post_id: number | null;
  game_key: string | null;
  pick_direction: string | null;
  posted_at: string | null;
  created_at: string;
  updated_at: string;
}

export interface KieAiTaskResult {
  taskId: string;
  status: 'pending' | 'processing' | 'completed' | 'failed';
  resultUrl?: string;
  error?: string;
}

export interface TwitterPostResult {
  tweetId: string;
  text: string;
}

export interface EngagementTarget {
  tweetId: string;
  authorId: string;
  authorUsername: string;
  text: string;
  likeCount: number;
  retweetCount: number;
  createdAt: string;
}

export interface ScheduleSlot {
  hour: number;
  slotName: string;
  dayOfWeek?: number[];    // 0=Sun..6=Sat, undefined = every day
  handler: () => Promise<number>;
}

export interface MediaCircuitState {
  consecutiveFailures: number;
  disabledUntil: Date | null;
}

export interface GrokTweetResponse {
  text: string;
  imagePrompt?: string;
  pickSide?: string;   // "home" | "away" | "over" | "under"
  gameHome?: string;   // returned by hot_take so we can identify which game was picked
  gameAway?: string;
}

export interface GrokThreadResponse {
  hook: string;
  parts: string[];
  imagePrompt?: string;
}

export interface EventDrivenAlert {
  type: 'line_move' | 'steam_move' | 'public_contrarian' | 'total_move';
  league: string;
  data: Record<string, unknown>;
}
