/**
 * Content Freshness domain types
 *
 * Types for decay pattern detection, freshness recommendations, and related features.
 */

// Decay pattern types (matches backend DecayPatternType enum)
export type DecayPatternType =
  | 'gradual_decay'
  | 'step_drop'
  | 'post_update_decline'
  | 'query_mix_erosion'
  | 'position_drift'
  | 'seasonal_normalized_decay'
  | 'volatility';

// Action types for freshness recommendations (matches backend ActionType enum)
export type FreshnessActionType =
  | 'light_refresh'
  | 'section_refresh'
  | 'full_rewrite'
  | 'reposition_intent';

// All action types including freshness and legacy
export type ActionType =
  | 'noindex'
  | 'content_rewrite'
  | 'meta_tag_optimization'
  | 'internal_linking'
  | 'thin_content'
  | FreshnessActionType;

// Page decay signal data
export interface PageDecaySignal {
  decay_pattern_type: DecayPatternType;
  baseline_7d_clicks: number;
  baseline_28d_clicks: number;
  baseline_90d_clicks: number;
  current_clicks: number;
  decay_magnitude: number;
  confidence_score: number;
  freshness_score: number;
  supporting_data: Record<string, unknown>;
  created_at: string;
}

// Page decay run summary
export interface PageDecayRun {
  id: number;
  status: 'pending' | 'processing' | 'completed' | 'failed';
  analysis_window_start: string;
  analysis_window_end: string;
  summary: Record<string, unknown> | null;
  completed_at: string | null;
}

// Freshness recommendation
export interface FreshnessRecommendation {
  id: number;
  page_url: string;
  action_type: ActionType;
  impact_score: number;
  confidence_score: number;
  effort_score: number;
  urgency_score: number;
  freshness_score: number;
  title: string;
  reasoning: string;
  evidence: Record<string, unknown>;
  status: string;
  created_at: string;
  page_decay_signal?: PageDecaySignal;
}

// WordPress post data (for content age context)
export interface WpPost {
  wp_post_id: number;
  title: string;
  url: string;
  wp_published_at: string | null;
  wp_modified_at: string | null;
  word_count: number | null;
  flesch_kincaid_score: number | null;
}

// Recommendation counts by action type
export interface FreshnessRecommendationCounts {
  total: number;
  light_refresh: number;
  section_refresh: number;
  full_rewrite: number;
  reposition_intent: number;
}

// Filters for freshness index page
export interface FreshnessFilters {
  action_type?: string;
  decay_pattern?: DecayPatternType;
  min_confidence?: string | number;
  sort_by?: 'impact' | 'urgency' | 'effort' | 'freshness';
}

// Site summary for freshness pages
export interface FreshnessSiteSummary {
  id: number;
  name: string;
  domain: string;
}

// Freshness Index page props
export interface FreshnessIndexPageProps {
  site: FreshnessSiteSummary;
  latestRun: PageDecayRun | null;
  recommendations: {
    data: FreshnessRecommendation[];
    current_page: number;
    last_page: number;
    per_page: number;
    total: number;
    from: number | null;
    to: number | null;
  };
  filters: FreshnessFilters;
  counts: FreshnessRecommendationCounts;
}

// Freshness Show page props
export interface FreshnessShowPageProps {
  site: FreshnessSiteSummary;
  recommendation: FreshnessRecommendation;
  decaySignal: PageDecaySignal | null;
  decayRun: Omit<PageDecayRun, 'status' | 'summary'>;
  wpPost: WpPost | null;
}

// Page refresh policy (for future use)
export interface PageRefreshPolicy {
  id: number;
  site_id: number;
  page_url: string;
  cadence: 'monthly' | 'quarterly' | 'event-driven' | 'evergreen';
  snoozed_until: string | null;
  notes: string | null;
  created_at: string;
  updated_at: string;
}
