import {z} from 'zod' export type GetApiTrainersTrainerIdScheduleArgs = {trainer_id: string}; export type GetApiTrainersTrainerIdScheduleOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const trainerSchedule = z.object({trainer_id: z.string().optional(), trainer_name: z.string().optional(), date: z.string().optional(), booking_typ_0000: z.enum(["0", "1"]).optional(), booking_typ_0030: z.enum(["0", "1"]).optional(), booking_typ_0100: z.enum(["0", "1"]).optional(), booking_typ_0130: z.enum(["0", "1"]).optional(), booking_typ_0200: z.enum(["0", "1"]).optional(), booking_typ_0230: z.enum(["0", "1"]).optional(), booking_typ_0300: z.string().optional(), booking_typ_0330: z.enum(["0", "1"]).optional(), booking_typ_0400: z.enum(["0", "1"]).optional(), booking_typ_0430: z.enum(["0", "1"]).optional(), booking_typ_0500: z.enum(["0", "1"]).optional(), booking_typ_0530: z.enum(["0", "1"]).optional(), booking_typ_0600: z.string().optional(), booking_typ_0630: z.enum(["0", "1"]).optional(), booking_typ_0700: z.enum(["0", "1"]).optional(), booking_typ_0730: z.enum(["0", "1"]).optional(), booking_typ_0800: z.enum(["0", "1"]).optional(), booking_typ_0830: z.enum(["0", "1"]).optional(), booking_typ_0900: z.enum(["0", "1"]).optional(), booking_typ_0930: z.enum(["0", "1"]).optional(), booking_typ_1000: z.enum(["0", "1"]).optional(), booking_typ_1030: z.enum(["0", "1"]).optional(), booking_typ_1100: z.enum(["0", "1"]).optional(), booking_typ_1130: z.enum(["0", "1"]).optional(), booking_typ_1200: z.enum(["0", "1"]).optional(), booking_typ_1230: z.enum(["0", "1"]).optional(), booking_typ_1300: z.enum(["0", "1"]).optional(), booking_typ_1330: z.enum(["0", "1"]).optional(), booking_typ_1400: z.enum(["0", "1"]).optional(), booking_typ_1430: z.enum(["0", "1"]).optional(), booking_typ_1500: z.enum(["0", "1"]).optional(), booking_typ_1530: z.enum(["0", "1"]).optional(), booking_typ_1600: z.enum(["0", "1"]).optional(), booking_typ_1630: z.enum(["0", "1"]).optional(), booking_typ_1700: z.enum(["0", "1"]).optional(), booking_typ_1730: z.enum(["0", "1"]).optional(), booking_typ_1800: z.enum(["0", "1"]).optional(), booking_typ_1830: z.enum(["0", "1"]).optional(), booking_typ_1900: z.enum(["0", "1"]).optional(), booking_typ_1930: z.string().optional(), booking_typ_2000: z.enum(["0", "1"]).optional(), booking_typ_2030: z.enum(["0", "1"]).optional(), booking_typ_2100: z.enum(["0", "1"]).optional(), booking_typ_2130: z.enum(["0", "1"]).optional(), booking_typ_2200: z.enum(["0", "1"]).optional(), booking_typ_2230: z.enum(["0", "1"]).optional(), booking_typ_2300: z.enum(["0", "1"]).optional(), booking_typ_2330: z.enum(["0", "1"]).optional()}); export const trainerSchedules = z.object({count: z.number().int().optional(), items: z.array(trainerSchedule).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 }; /** * API011 トレーナースケジュール取得 * * GET /trainers/{trainer_id}/schedule */ export const getApiTrainersTrainerIdSchedule = async (args: GetApiTrainersTrainerIdScheduleArgs, options: GetApiTrainersTrainerIdScheduleOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/trainers/${encodeURIComponent(String(args.trainer_id))}/schedule${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(trainerSchedules, await res.json()) };