/**
 * API модуль для предметов
 */

import apiClient from '@/lib/api-client';

export interface Subject {
  id: number;
  name: string;
  description?: string;
}

export interface MentorSubject {
  id: number;
  name: string;
  mentor: number;
  created_at?: string;
}

/**
 * Получить список общих предметов
 */
export async function getSubjects(search?: string): Promise<Subject[]> {
  const params = search ? { search } : {};
  const response = await apiClient.get<Subject[] | { results: Subject[] }>('/schedule/subjects/', { params });
  const data = response.data;
  return Array.isArray(data) ? data : (data?.results ?? []);
}

/**
 * Получить список предметов ментора
 */
export async function getMentorSubjects(): Promise<MentorSubject[]> {
  const response = await apiClient.get<MentorSubject[] | { results: MentorSubject[] }>('/schedule/mentor-subjects/');
  const data = response.data;
  return Array.isArray(data) ? data : (data?.results || []);
}

/**
 * Создать кастомный предмет ментора
 */
export async function createMentorSubject(name: string): Promise<MentorSubject> {
  const response = await apiClient.post<MentorSubject>('/schedule/mentor-subjects/', { name });
  return response.data;
}
