import {z} from 'zod' export type OnlyId = {id?: string | undefined}; export type TicketAssignmentRule = {id?: string | undefined, version?: string | undefined, assignedPoolingGroupId?: string | undefined, assigneeUserId?: string | undefined, businessHolidaysId?: string | undefined, commercialLanguage?: string | undefined, createdDate?: number | undefined, distributionChannel?: string | undefined, lastModifiedDate?: number | undefined, parties?: Array | undefined, responsibleUserId?: string | undefined, targetStatusId?: string | undefined, ticketAssigneeType?: ('CUSTOMER_RESPONSIBLE_PERSON' | 'POOL' | 'TICKET_AGENT') | undefined, ticketCategoryId?: string | undefined, ticketChannelId?: string | undefined, ticketPriorityId?: string | undefined, ticketTypeId?: string | undefined, workScheduleProfileId?: string | undefined}; export type UpdateApiTicketAssignmentRuleIdIdArgs = {id: string, dryRun?: boolean | undefined, body: TicketAssignmentRule}; export type UpdateApiTicketAssignmentRuleIdIdOptions = {baseUrl: string, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const onlyId = z.object({id: z.string().optional()}); export const ticketAssignmentRule = z.object({id: z.string().optional(), version: z.string().optional(), assignedPoolingGroupId: z.string().optional(), assigneeUserId: z.string().optional(), businessHolidaysId: z.string().optional(), commercialLanguage: z.string().optional(), createdDate: z.number().int().optional(), distributionChannel: z.string().optional(), lastModifiedDate: z.number().int().optional(), parties: z.array(onlyId).optional(), responsibleUserId: z.string().optional(), targetStatusId: z.string().optional(), ticketAssigneeType: z.enum(["CUSTOMER_RESPONSIBLE_PERSON", "POOL", "TICKET_AGENT"]).optional(), ticketCategoryId: z.string().optional(), ticketChannelId: z.string().optional(), ticketPriorityId: z.string().optional(), ticketTypeId: z.string().optional(), workScheduleProfileId: 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 }; /** * update ticketAssignmentRule * * PUT /ticketAssignmentRule/id/{id} */ export const updateApiTicketAssignmentRuleIdId = async (args: UpdateApiTicketAssignmentRuleIdIdArgs, options: UpdateApiTicketAssignmentRuleIdIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.dryRun != null) query.append("dryRun", String(args.dryRun)) if (APIToken !== undefined) headers.set("AuthenticationToken", APIToken) const url = `${baseUrl.replace(/\/+$/, '')}/ticketAssignmentRule/id/${encodeURIComponent(String(args.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(ticketAssignmentRule, await res.json()) };