export interface Rider {
  id: string
  telegram_id: number | null
  telegram_username: string | null
  avatar_url: string | null
  name: string
  ftp: number | null
  lthr: number | null
  weight: number | null
  zones_config: Record<string, unknown> | null
  goals: string | null
  experience_level: string | null
  coaching_profile: Record<string, unknown> | null
  onboarding_completed: boolean
}

export interface ActivityMetrics {
  tss: number | null
  normalized_power: number | null
  intensity_factor: number | null
  variability_index: number | null
  avg_power: number | null
  max_power: number | null
  avg_hr: number | null
  max_hr: number | null
  avg_cadence: number | null
  avg_speed: number | null
  calories: number | null
}

export interface Interval {
  id: string
  start_ts: string
  end_ts: string
  interval_type: string
  avg_power: number | null
  avg_hr: number | null
  duration: number | null
}

export interface ExerciseSet {
  exercise_name: string
  exercise_category: string | null
  repetitions: number | null
  weight: number | null
  duration: number | null
  start_time: string | null
}

export interface Activity {
  id: string
  rider_id: string
  name: string | null
  activity_type: string
  date: string
  duration: number
  distance: number | null
  elevation_gain: number | null
  metrics: ActivityMetrics | null
  intervals: Interval[]
  exercise_sets: ExerciseSet[] | null
  training_plan_id: string | null
  plan_week: number | null
  plan_day: string | null
}

export interface DataPoint {
  timestamp: string
  power: number | null
  heart_rate: number | null
  cadence: number | null
  speed: number | null
  latitude: number | null
  longitude: number | null
  altitude: number | null
  temperature: number | null
}

export interface ZoneItem {
  zone: number
  name: string
  seconds: number
  percentage: number
}

export interface PowerZoneItem extends ZoneItem {
  min_watts: number
  max_watts: number | null
}

export interface HrZoneItem extends ZoneItem {
  min_bpm: number
  max_bpm: number | null
}

export interface ZonesResponse {
  power_zones: PowerZoneItem[]
  hr_zones: HrZoneItem[]
}

export interface PowerCurveResponse {
  curve: Record<number, number>
}

export interface DiaryEntry {
  rider_notes: string | null
  mood: string | null
  rpe: number | null
  sleep_hours: number | null
}

export interface WeeklyStats {
  week: string
  rides: number
  duration: number
  distance: number
  tss: number
}

export interface PersonalRecord {
  duration: number
  power: number
  activity_id: string
  activity_name: string
  date: string
}

export interface FitnessEntry {
  date: string
  ctl: number
  atl: number
  tsb: number
  ramp_rate: number | null
}

export interface ChatMessage {
  role: 'user' | 'model'
  text: string
  timestamp?: string
}

export interface CoachingChat {
  chat_id: string
  chat_type: string
  status: string
  messages: ChatMessage[]
  onboarding_completed?: boolean
}

export interface ChatListItem {
  id: string
  chat_type: string
  status: string
  message_count: number
  created_at: string | null
  updated_at: string | null
  last_message: string | null
}

export interface TrainingPlanWeekDay {
  day: string
  workout_type: string
  title: string
  description: string
  duration_minutes: number
  target_tss: number
  target_if: number
}

export interface TrainingPlanWeek {
  week_number: number
  focus: string
  target_tss: number
  target_hours: number
  days: TrainingPlanWeekDay[]
}

export interface TrainingPlan {
  id: string
  goal: string
  start_date: string
  end_date: string
  phase: string | null
  description: string | null
  status: string
  weeks: TrainingPlanWeek[]
}

export interface ComplianceDayStatus {
  day: string
  planned: string
  workout_type: string
  activity_id: string | null
  completed: boolean
}

export interface ComplianceWeek {
  week_number: number
  focus: string
  planned_tss: number
  actual_tss: number
  planned_hours: number
  actual_hours: number
  planned_rides: number
  actual_rides: number
  adherence_pct: number
  status: string
  days: ComplianceDayStatus[]
}

export interface CalendarDay {
  date: string
  count: number
  duration: number
  tss: number
}

export interface MonthlyTrend {
  month: string
  rides: number
  hours: number
  distance_km: number
  avg_power: number | null
  avg_np: number | null
  avg_hr: number | null
  tss: number
  w_per_kg: number | null
}

export interface FtpDetection {
  detected_ftp: number | null
  best_20min_power: number | null
  activity_id: string | null
  activity_name: string | null
  date: string | null
  current_ftp: number | null
  message?: string
}

export interface WeeklyDigest {
  digest: string | null
  message?: string
  week_start: string
  week_end: string
  total_activities: number
  total_hours: number
  total_tss: number
  total_distance_km: number
}

export interface PeriodStats {
  rides: number
  hours: number
  distance_km: number
  tss: number
  avg_power: number | null
  avg_np: number | null
  avg_hr: number | null
}

export interface FitnessSnapshot {
  ctl: number | null
  atl: number | null
  tsb: number | null
}

export interface ProgressSummary {
  this_week: PeriodStats
  last_week: PeriodStats
  this_month: PeriodStats
  last_month: PeriodStats
  fitness: FitnessSnapshot
  fitness_7d_ago: FitnessSnapshot
  total_activities: number
  days_since_last_activity: number | null
  ftp: number | null
  weight: number | null
}

export interface TodayWorkout {
  plan_id: string
  plan_goal: string
  week_number: number
  week_focus: string
  day: string
  workout_type: string
  title: string
  description: string
  duration_minutes: number
  target_tss: number
  target_if: number
  linked_activity_id: string | null
  completed: boolean
}
