import { WorkoutPlan } from '../types';
import { api } from './api';

interface ApiResponse<T> {
    success: boolean;
    data: T;
    error?: string;
}

export const getPlans = async (userId: string): Promise<WorkoutPlan[]> => {
    try {
        const res = await api.get<ApiResponse<WorkoutPlan[]>>('/plans');
        return res.data || [];
    } catch {
        return [];
    }
};

export const savePlan = async (userId: string, plan: WorkoutPlan): Promise<void> => {
    await api.post<ApiResponse<any>>('/plans', plan);
};

export const deletePlan = async (userId: string, id: string): Promise<void> => {
    await api.delete<ApiResponse<any>>(`/plans/${id}`);
};
