import http from '@/http';
import type {Session} from '@/types/stage';

export type FormationSession = Session & {fssId: number; fssFst: {fstId: number}};

export async function getFormationSession(fssId: string): Promise<FormationSession> {
  if (!fssId || fssId.trim() === '') {
    throw new Error('fssId is required');
  }

  try {
    const response = await http.get(`/formation_sessions/${fssId}`);
    return response.data;
  } catch (error: unknown) {
    const httpError = error as {response?: {status: number}};
    if (httpError.response?.status === 404) {
      throw new Error(`Formation session not found for ID: ${fssId}`);
    }
    throw error;
  }
}
