import {z} from 'zod' export type UpdateCourseClassScheduleRequest = {start_date?: (string | null) | undefined, quiz_start_date?: (string | null) | undefined, quiz_end_date?: (string | null) | undefined}; export type UpdateApiTeacherCoursesCourseIdAssignmentSchedulesClassIdArgs = {course_id: string, class_id: string, body: UpdateCourseClassScheduleRequest}; export type UpdateApiTeacherCoursesCourseIdAssignmentSchedulesClassIdOptions = {baseUrl: string, OAuth2PasswordBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const bookmarkPosition = z.object({kind: z.enum(["unset", "nothing", "unit", "block"]), unit_id: z.string().nullable().optional(), block_id: z.string().nullable().optional()}); export const courseClassScheduleOut = z.object({class_id: z.string(), class_name: z.string().optional(), school_year: z.string().nullable().optional(), is_past: z.boolean().optional(), start_date: z.string().nullable().optional(), quiz_start_date: z.string().nullable().optional(), quiz_end_date: z.string().nullable().optional(), bookmark: bookmarkPosition.optional()}); export const courseComponentSharingOptions = z.object({include_content_units: z.boolean().optional(), include_qcm_units: z.boolean().optional(), include_flashcard_units: z.boolean().optional(), include_global_flashcards: z.boolean().optional(), include_knowledge_quiz: z.boolean().optional(), excluded_unit_ids: z.array(z.string()).optional()}); export const knowledgeQuizSettings = z.object({is_enabled: z.boolean().optional(), max_attempts: z.number().int().nullable().optional(), show_correct_answers_after: z.boolean().optional(), start_date: z.string().nullable().optional(), end_date: z.string().nullable().optional(), format: z.enum(["paper", "app"]).optional()}); export const courseAssignmentDetails = z.object({id: z.string().nullable().optional(), teacher_id: z.string().nullable().optional(), course_id: z.string(), class_ids: z.array(z.string()).optional(), class_schedules: z.array(courseClassScheduleOut).optional(), frozen_school_years: z.array(z.string()).optional(), assigned_at: z.string().nullable().optional(), start_date: z.string().nullable().optional(), is_visible_to_students: z.boolean().optional(), due_date: z.string().nullable().optional(), instructions: z.string().nullable().optional(), sharing_options: courseComponentSharingOptions.optional(), knowledge_quiz_settings: knowledgeQuizSettings.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 }; /** * Update Course Class Schedule * * PUT /teacher/courses/{course_id}/assignment/schedules/{class_id} */ export const updateApiTeacherCoursesCourseIdAssignmentSchedulesClassId = async (args: UpdateApiTeacherCoursesCourseIdAssignmentSchedulesClassIdArgs, options: UpdateApiTeacherCoursesCourseIdAssignmentSchedulesClassIdOptions) => { 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/courses/${encodeURIComponent(String(args.course_id))}/assignment/schedules/${encodeURIComponent(String(args.class_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(courseAssignmentDetails, await res.json()) };