import type { MusicVibe } from './workout'

/**
 * Workout Program Types
 * Body Zone + Difficulty model
 * Program = 3 Tabatas, each Tabata = 2 exercises × 8 rounds
 */

// ─── Enums ──────────────────────────────────────────────────────

export type BodyZone = 'upper-body' | 'lower-body' | 'full-body'

export type ProgramLevel = 'Beginner' | 'Intermediate' | 'Advanced'

// ─── Exercise ───────────────────────────────────────────────────

export interface ProgramExercise {
  name: string
  nameEn: string
  tip?: string
  tipEn?: string
  modification?: string
  modificationEn?: string
  progression?: string
  progressionEn?: string
}

// ─── Tabata ─────────────────────────────────────────────────────

export interface WorkoutTabata {
  id: string
  position: 1 | 2 | 3
  exercise1: ProgramExercise
  exercise2: ProgramExercise
  rounds: number
  workTime: number
  restTime: number
}

// ─── Program ────────────────────────────────────────────────────

export interface WorkoutProgram {
  id: string
  title: string
  description: string | null
  bodyZone: BodyZone
  level: ProgramLevel
  isFree: boolean
  musicVibe: MusicVibe
  estimatedDuration: number
  estimatedCalories: number
  icon: string | null
  accentColor: string | null
  sortOrder: number
  tabatas: WorkoutTabata[]
  createdAt: string
  updatedAt: string
}

// ─── Supabase Row Types ─────────────────────────────────────────

export interface WorkoutProgramRow {
  id: string
  title: string
  description: string | null
  body_zone: BodyZone
  level: ProgramLevel
  is_free: boolean
  music_vibe: MusicVibe
  estimated_duration: number
  estimated_calories: number
  icon: string | null
  accent_color: string | null
  sort_order: number
  created_at: string
  updated_at: string
}

export interface WorkoutTabataRow {
  id: string
  program_id: string
  position: 1 | 2 | 3
  exercise_1_name: string
  exercise_1_name_en: string | null
  exercise_1_tip: string | null
  exercise_1_tip_en: string | null
  exercise_1_modification: string | null
  exercise_1_modification_en: string | null
  exercise_1_progression: string | null
  exercise_1_progression_en: string | null
  exercise_2_name: string
  exercise_2_name_en: string | null
  exercise_2_tip: string | null
  exercise_2_tip_en: string | null
  exercise_2_modification: string | null
  exercise_2_modification_en: string | null
  exercise_2_progression: string | null
  exercise_2_progression_en: string | null
  rounds: number
  work_time: number
  rest_time: number
  created_at: string
}

// ─── Display Metadata ───────────────────────────────────────────

export const BODY_ZONE_META: Record<BodyZone, {
  label: string
  labelEn: string
  icon: string
  color: string
}> = {
  'upper-body': {
    label: 'Haut du corps',
    labelEn: 'Upper Body',
    icon: 'figure.strengthtraining.traditional',
    color: '#4A90D9',
  },
  'lower-body': {
    label: 'Bas du corps',
    labelEn: 'Lower Body',
    icon: 'figure.run',
    color: '#9B59B6',
  },
  'full-body': {
    label: 'Corps entier',
    labelEn: 'Full Body',
    icon: 'figure.cooldown',
    color: '#00C896',
  },
}

export const LEVEL_META: Record<ProgramLevel, { label: string; labelEn: string; color: string }> = {
  Beginner: { label: 'Débutant', labelEn: 'Beginner', color: '#30D158' },
  Intermediate: { label: 'Intermédiaire', labelEn: 'Intermediate', color: '#FF9500' },
  Advanced: { label: 'Avancé', labelEn: 'Advanced', color: '#FF453A' },
}
