export type User = {
  id: string;
  email: string;
  display_name: string;
  created_at: string;
};

export type CatalogKind = "exercise" | "machine";
export type SourceKind = CatalogKind | "equipment";
export type ActivityCategory = "chest" | "back" | "legs" | "shoulders" | "biceps" | "triceps" | "core" | "cardio" | "full_body" | "other";
export type ActivityEquipment = "barbell" | "dumbbell" | "machine" | "cable" | "bodyweight" | "kettlebell" | "cardio_machine" | "other";
export type MeasurementType = "weight_reps" | "reps_only" | "duration" | "distance_duration" | "duration_calories";
export type Difficulty = "beginner" | "intermediate" | "advanced";

export type CatalogEntity = {
  id: string;
  owner_user_id: string | null;
  slug: string;
  kind: CatalogKind;
  title: string;
  description: string | null;
  category: ActivityCategory;
  equipment: ActivityEquipment;
  measurement_type: MeasurementType;
  difficulty: Difficulty;
  image_s3_url: string | null;
  image_s3_key: string | null;
  is_builtin: boolean;
  default_calories_per_minute?: number | null;
};

export type CatalogCreateInput = {
  slug?: string | null;
  kind: CatalogKind;
  title: string;
  description?: string | null;
  category: ActivityCategory;
  equipment: ActivityEquipment;
  measurement_type: MeasurementType;
  difficulty: Difficulty;
  image_s3_url?: string | null;
  image_s3_key?: string | null;
};

export type WorkoutStatus = "active" | "finished" | "discarded";

export type WorkoutSet = {
  id: string;
  workout_item_id: string;
  set_index: number;
  weight: number;
  reps: number;
  duration_seconds: number | null;
  distance_km: number | null;
  calories: number | null;
  completed_at: string;
};

export type WorkoutItem = {
  id: string;
  workout_id: string;
  source_kind: SourceKind;
  activity_source_id: string | null;
  exercise_id: string | null;
  equipment_id: string | null;
  title_snapshot: string;
  image_s3_url_snapshot: string | null;
  measurement_type_snapshot: MeasurementType;
  category_snapshot: ActivityCategory;
  equipment_snapshot: ActivityEquipment;
  order_index: number;
  planned_working_weight: number | null;
  created_at: string;
  sets: WorkoutSet[];
};

export type Workout = {
  id: string;
  user_id: string;
  status: WorkoutStatus;
  started_at: string;
  finished_at: string | null;
  notes: string | null;
  total_sets: number;
  total_volume: number;
  estimated_calories: number;
  created_at?: string;
  updated_at?: string;
  items: WorkoutItem[];
};

export type Progression = {
  last_weight: number | null;
  max_weight: number | null;
  previous_delta: number | null;
  points: Array<{ date: string; max_weight: number; volume: number }>;
};

export type Calories = {
  total_calories: number;
  workouts: Array<{ id: string; date: string; calories: number }>;
};

export type WorkoutSetInput = {
  weight: number;
  reps: number;
  duration_seconds?: number | null;
  distance_km?: number | null;
  calories?: number | null;
};
