import {z} from 'zod' export type GetApiTicketStatusIdIdArgs = {id: string}; export type GetApiTicketStatusIdIdOptions = {baseUrl: string, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const ticketStatus = z.object({id: z.string().optional(), version: z.string().optional(), autoChangeDays: z.number().int().optional(), autoChangeTicketStatusId: z.string().optional(), color: z.enum(["BLUE", "BROWN", "DARK_BLUE", "DARK_GREEN", "DARK_RED", "GREEN", "LIGHT_BLUE", "ORANGE", "PINK", "PURPLE", "RED", "VIOLET", "YELLOW", "YELLOW_GREEN"]).optional(), createdDate: z.number().int().optional(), defaultForInternal: z.boolean().optional(), internalTicketStatus: z.enum(["CLOSED", "FIXED", "IN_PROGRESS", "POOL", "UNASSIGNED", "WAITING"]).optional(), lastModifiedDate: z.number().int().optional(), name: z.string(), positionNumber: z.number().int().optional(), targetStatusId: z.string().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 }; /** * query ticketStatus * * GET /ticketStatus/id/{id} */ export const getApiTicketStatusIdId = async (args: GetApiTicketStatusIdIdArgs, options: GetApiTicketStatusIdIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIToken !== undefined) headers.set("AuthenticationToken", APIToken) const url = `${baseUrl.replace(/\/+$/, '')}/ticketStatus/id/${encodeURIComponent(String(args.id))}${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(ticketStatus, await res.json()) };