import {z} from 'zod' export type PatchedInventoryGroupTarif = {id?: number | undefined, weekdays?: Array | undefined, created_at?: string | undefined, updated_at?: string | undefined, start?: (string | null) | undefined, end?: (string | null) | undefined, published?: boolean | undefined, order?: number | undefined, name?: string | undefined, price?: unknown | undefined, tenant?: number | undefined, inventory?: (number | null) | undefined, inventory_group?: (number | null) | undefined, inventory_set?: (number | null) | undefined, inventory_set_price?: (number | null) | undefined, time_period?: (number | null) | undefined}; export type PatchApiV1CrmGroupsGroupIdTarifsTarifIdArgs = {group_id: number, tarif_id: number, body: PatchedInventoryGroupTarif}; export type PatchApiV1CrmGroupsGroupIdTarifsTarifIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const inventoryGroupTarif = z.object({id: z.number().int(), weekdays: z.array(z.number().int()).optional(), created_at: z.string(), updated_at: z.string(), start: z.string().nullable().optional(), end: z.string().nullable().optional(), published: z.boolean().optional(), order: z.number().int().gte(-2147483648).lte(2147483647).optional(), name: z.string().max(255).optional(), price: z.string().optional(), tenant: z.number().int().optional(), inventory: z.number().int().nullable(), inventory_group: z.number().int().nullable().optional(), inventory_set: z.number().int().nullable().optional(), inventory_set_price: z.number().int().nullable().optional(), time_period: z.number().int().nullable().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 }; /** * PATCH /v1/crm/groups/{group_id}/tarifs/{tarif_id}/ */ export const patchApiV1CrmGroupsGroupIdTarifsTarifId = async (args: PatchApiV1CrmGroupsGroupIdTarifsTarifIdArgs, options?: PatchApiV1CrmGroupsGroupIdTarifsTarifIdOptions) => { const {baseUrl = "https://api.yume.cloud", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/crm/groups/${encodeURIComponent(String(args.group_id))}/tarifs/${encodeURIComponent(String(args.tarif_id))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(inventoryGroupTarif, await res.json()) };