import {
  Workout,
  SetLog,
  Exercise,
} from "@prisma/client";

/**
 * SetLog with associated Exercise
 */
export type SetLogWithExercise = SetLog & {
  exercise: Exercise;
};

/**
 * Workout with all its sets and exercises
 */
export type WorkoutWithSets = Workout & {
  setLogs: SetLogWithExercise[];
};

/**
 * Exercise with last used date and personal best info
 */
export type ExerciseWithStats = Exercise & {
  lastUsed?: Date | null;
  personalBest?: {
    weight: number;
    reps: number;
    date: Date;
  } | null;
};

/**
 * Dashboard statistics
 */
export type DashboardStats = {
  totalWorkouts: number;
  totalVolume: number;
  totalSets: number;
  totalReps: number;
  personalBests: Array<{
    exerciseId: string;
    exerciseName: string;
    weight: number;
    reps: number;
    date: Date;
  }>;
  recentWorkouts: WorkoutWithSets[];
};

/**
 * Search and filter options
 */
export type SearchFilters = {
  query?: string;
  exerciseId?: string;
  dateFrom?: Date;
  dateTo?: Date;
  limit?: number;
  offset?: number;
};

/**
 * Pagination metadata
 */
export type PaginationMeta = {
  total: number;
  limit: number;
  offset: number;
  hasMore: boolean;
};

/**
 * Paginated response wrapper
 */
export type PaginatedResponse<T> = {
  data: T[];
  meta: PaginationMeta;
};

/**
 * Import feature — parsed workout data from Claude vision
 */
export type ParsedSet = {
  reps?: number | null;
  weight?: number | null;
  weightUnit?: string | null;
  durationSeconds?: number | null;
  distance?: number | null;
  distanceUnit?: string | null;
  calories?: number | null;
  rpe?: number | null;
  notes?: string | null;
};

export type ParsedExercise = {
  name: string;
  type?: string;
  sets: ParsedSet[];
  notes?: string;
  /** Flag from Claude when it's unsure about this exercise */
  uncertain?: boolean;
  uncertainReason?: string;
};

export type ParsedWorkout = {
  date: string; // ISO date string
  name?: string;
  notes?: string;
  exercises: ParsedExercise[];
};

export type ImportParseResponse = {
  workouts: ParsedWorkout[];
  confidence: "high" | "medium" | "low";
  warnings: string[];
};

export type ReviewedWorkout = {
  date: string;
  name?: string;
  notes?: string;
  exercises: {
    name: string;
    type?: string;
    existingExerciseId?: string; // if matched to library
    sets: ParsedSet[];
  }[];
};
