-- Exercise Timing & Workout Execution Tracking
-- Tracks per-exercise start/end times, time taken, and rest time between exercises

-- 1. Exercise Timing (per-exercise timing within a session)
CREATE TABLE IF NOT EXISTS workout_exercise_timing (
  id TEXT PRIMARY KEY,
  session_id TEXT NOT NULL REFERENCES workout_sessions(id) ON DELETE CASCADE,
  exercise_id TEXT NOT NULL,
  exercise_name TEXT DEFAULT '',
  order_index INTEGER DEFAULT 0,
  start_time DATETIME,
  end_time DATETIME,
  time_taken_seconds INTEGER DEFAULT 0,
  rest_time_seconds INTEGER DEFAULT 0,
  sets_done INTEGER DEFAULT 0,
  reps_done INTEGER DEFAULT 0,
  completed INTEGER DEFAULT 0,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  UNIQUE(session_id, exercise_id)
);

-- 2. User Workout Days Setting (workout days per week preference)
CREATE TABLE IF NOT EXISTS user_workout_settings (
  id TEXT PRIMARY KEY,
  user_id TEXT NOT NULL UNIQUE,
  workout_days_per_week INTEGER DEFAULT 3,
  updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

-- Indexes
CREATE INDEX IF NOT EXISTS idx_exercise_timing_session ON workout_exercise_timing(session_id);
CREATE INDEX IF NOT EXISTS idx_exercise_timing_exercise ON workout_exercise_timing(exercise_id);
