import {z} from 'zod' export type GetApiDesksIdServicesCatalogsItemsArgs = {id: number, area_id?: number | undefined, catalog_id?: number | undefined, name?: string | undefined, offset?: number | undefined, limit?: number | undefined}; export type GetApiDesksIdServicesCatalogsItemsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiDesksIdServicesCatalogsItemsResponse = z.array(z.object({id: z.number().int(), name: z.string(), area: z.object({id: z.number().int(), name: z.string()}), catalog: z.object({id: z.number().int(), name: z.string()}), start_time: z.string().nullable(), end_time: z.string().nullable()})); 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 }; /** * Listar itens de catálogos de serviços * * GET /desks/{id}/services-catalogs-items */ export const getApiDesksIdServicesCatalogsItems = async (args: GetApiDesksIdServicesCatalogsItemsArgs, options?: GetApiDesksIdServicesCatalogsItemsOptions) => { const {baseUrl = "https://api.tiflux.com/api/v2", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.area_id != null) query.append("area_id", String(args.area_id)) if (args.catalog_id != null) query.append("catalog_id", String(args.catalog_id)) if (args.name != null) query.append("name", String(args.name)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/desks/${encodeURIComponent(String(args.id))}/services-catalogs-items${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(getApiDesksIdServicesCatalogsItemsResponse, await res.json()) };