import { getDBConnection } from '../sqlite';
import { Workout } from '@/types/workout.types';

export const workoutRepository = {
  async getAllWorkouts(): Promise<Workout[]> {
    const db = await getDBConnection();
    return db.getAllAsync('SELECT * FROM workouts ORDER BY start_time DESC');
  },
  
  async getWorkoutById(id: string): Promise<Workout | null> {
    const db = await getDBConnection();
    return db.getFirstAsync('SELECT * FROM workouts WHERE id = ?', [id]);
  },
  
  async deleteWorkout(id: string): Promise<void> {
    const db = await getDBConnection();
    await db.runAsync('DELETE FROM workouts WHERE id = ?', [id]);
  }
};
