import {z} from 'zod' export type WorkingHourTable = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11; export type WorkingHour = {id?: number | undefined, departmentIds?: (string | null) | undefined, groupIndex?: number | undefined, dayIndis?: number | undefined, tableType?: WorkingHourTable | undefined, tableId?: number | undefined, startTime?: (string | null) | undefined, endTime?: (string | null) | undefined}; export type UpdateApiV1ChatbotsIdWorkingHoursArgs = {id: number, body: Array}; export type UpdateApiV1ChatbotsIdWorkingHoursOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const workingHourTable = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6), z.literal(7), z.literal(8), z.literal(9), z.literal(10), z.literal(11)]); export const workingHour = z.object({id: z.number().int().optional(), departmentIds: z.string().nullable().optional(), groupIndex: z.number().int().optional(), dayIndis: z.number().int().optional(), tableType: workingHourTable.optional(), tableId: z.number().int().optional(), startTime: z.string().nullable().optional(), endTime: z.string().nullable().optional()}); export const updateApiV1ChatbotsIdWorkingHoursResponse = z.array(workingHour); 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 }; /** * Replace the chatbot's custom working hours. An empty list clears them. * * PUT /v1/chatbots/{id}/working-hours * * Also accepts auth: API Key */ export const updateApiV1ChatbotsIdWorkingHours = async (args: UpdateApiV1ChatbotsIdWorkingHoursArgs, options: UpdateApiV1ChatbotsIdWorkingHoursOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/chatbots/${encodeURIComponent(String(args.id))}/working-hours${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(updateApiV1ChatbotsIdWorkingHoursResponse, await res.json()) };