import {z} from 'zod' export type TeacherExerciseEditRequest = {title?: (string | null) | undefined, content?: (string | null) | undefined, solution?: (string | null) | undefined, figure_id?: (string | null) | undefined, solution_figure_id?: (string | null) | undefined, figure_content?: (string | null) | undefined, figure_solution?: (string | null) | undefined, difficulty?: (string | null) | undefined, themes?: (Array | null) | undefined, edit_method?: string | undefined}; export type CreateApiTeacherExercisesExerciseIdEditLatexArgs = {exercise_id: string, body: TeacherExerciseEditRequest}; export type CreateApiTeacherExercisesExerciseIdEditLatexOptions = {baseUrl: string, OAuth2PasswordBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const teacherExerciseResponse = z.object({id: z.string(), teacher_id: z.string(), title: z.string().nullable(), content: z.string(), solution: z.string().nullable(), figure_id: z.string().nullable().optional(), solution_figure_id: z.string().nullable().optional(), figure_content: z.string().nullable().optional(), figure_solution: z.string().nullable().optional(), difficulty: z.string().nullable(), themes: z.array(z.string()), source: z.string(), subject: z.enum(["maths", "physique-chimie"]).optional(), grade: z.enum(["sixieme", "cinquieme", "quatrieme", "troisieme", "seconde", "premiere", "terminale", "prepa"]).nullable().optional(), created_at: z.string(), updated_at: z.string(), is_private: z.boolean(), is_saved: z.boolean(), folder_id: z.string().nullable().optional(), likes_count: z.number().int().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Edit Exercise Latex * * POST /teacher_exercises/{exercise_id}/edit-latex */ export const createApiTeacherExercisesExerciseIdEditLatex = async (args: CreateApiTeacherExercisesExerciseIdEditLatexArgs, options: CreateApiTeacherExercisesExerciseIdEditLatexOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2PasswordBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2PasswordBearer !== undefined) headers.set('authorization', `Bearer ${OAuth2PasswordBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/teacher_exercises/${encodeURIComponent(String(args.exercise_id))}/edit-latex${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(teacherExerciseResponse, await res.json()) };