const BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:5123';

export interface CheckFileRequest {
  fileContent: string;
  fileName: string;
  checkType: 'language' | 'content';
}

export interface CheckFileResponse {
  result: string;
}

export interface GenerateFlashcardsRequest {
  fileContent: string;
  fileName: string;
  amount: number;
  mode: FlashcardMode;
}

export type FlashcardMode = 'Basic' | 'Simple' | 'Detailed' | 'Hyper';

export interface GenerateFlashcardsResponse {
  result: string;
}

export const MindforgeApiService = {
  async checkFile(data: CheckFileRequest): Promise<CheckFileResponse> {
    const response = await fetch(`${BASE_URL}/api/v1/file/check`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(data),
    });

    if (!response.ok) {
      throw new Error(`Error checking file: ${response.statusText}`);
    }
    return response.json();
  },

  async generateFlashcards(data: GenerateFlashcardsRequest): Promise<GenerateFlashcardsResponse> {
    const response = await fetch(`${BASE_URL}/api/v1/flashcard/generate`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(data),
    });

    if (!response.ok) {
      throw new Error(`Error generating flashcards: ${response.statusText}`);
    }
    return response.json();
  }
};
