export type InstructorCourse = { id: string; slug: string; title: string; subtitle?: string | null; description?: string | null; organizationName: string; teacher?: { id: string; name?: string | null; email: string; }; }; const LMS_API_BASE_URL = (import.meta.env.VITE_API_BASE_URL ?? 'https://workspace.autonomystudio.net/lms-api/api').replace(/\/+$/, ''); export async function listInstructorCourses(accessToken: string): Promise<{ courses: InstructorCourse[] }> { const response = await fetch(`${LMS_API_BASE_URL}/instructor/courses`, { headers: { Authorization: `Bearer ${accessToken}`, }, }); if (!response.ok) throw new Error(`강좌 목록을 불러오지 못했습니다. (${response.status})`); return response.json() as Promise<{ courses: InstructorCourse[] }>; } export async function createInitialInstructorCourse(accessToken: string, title: string): Promise<{ course: InstructorCourse }> { const response = await fetch(`${LMS_API_BASE_URL}/instructor/courses/initial`, { method: 'POST', headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ title }), }); if (!response.ok) { const payload = await response.json().catch(() => null) as { message?: string } | null; throw new Error(payload?.message || `강좌를 생성하지 못했습니다. (${response.status})`); } return response.json() as Promise<{ course: InstructorCourse }>; }