import {z} from 'zod' export type GetApiV1CrmMetricsWorkshopsResourcesArgs = {client?: number | undefined, created_at__date__gte?: string | undefined, created_at__date__lte?: string | undefined, created_by?: number | undefined, inventory?: number | undefined, ordering?: string | undefined, page?: number | undefined, pageSize?: number | undefined, search?: string | undefined, status?: (0 | 1 | 2 | 3) | undefined, type?: (0 | 1) | undefined, worker?: number | undefined}; export type GetApiV1CrmMetricsWorkshopsResourcesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const disabledEnum = z.union([z.literal(0), z.literal(1), z.literal(2)]); export const nullEnum = z.unknown(); export const baseInventory = z.object({id: z.number().int(), group: z.number().int().nullable().optional(), name: z.string().max(255), unique_id: z.string().max(255).nullable().optional(), category: z.number().int().nullable().optional(), image: z.string().nullable().optional(), extra: z.unknown(), sublease_user: z.number().int().nullable().optional(), state: z.number().int().nullable().optional(), disabled: z.union([disabledEnum, nullEnum]).nullable().optional(), rental_point: z.number().int().nullable().optional()}); export const unitTypeEnum = z.enum(["litre", "kg", "g", "ml", "piece", "m3"]); export const type9ddEnum = z.union([z.literal(0), z.literal(1)]); export const baseInventoryGroup = z.object({id: z.number().int(), name: z.string().max(512).nullable().optional(), created_at: z.string(), deleted: z.boolean().optional(), updated_at: z.string(), category: z.number().int().nullable().optional(), unit_price: z.string().optional(), unit_count: z.string().optional(), unit_type: unitTypeEnum.optional(), unit_sum: z.string().optional(), image: z.string().nullable().optional(), unique_id: z.string().max(255).nullable().optional(), barcode: z.string().max(255).nullable().optional(), extra: z.unknown(), filters: z.array(z.string().max(32)).nullable().optional(), points: z.array(z.number().int().gte(-2147483648).lte(2147483647)).optional(), published: z.boolean().optional(), type: type9ddEnum.optional(), price: z.string().optional(), lifetime: z.number().int().gte(-2147483648).lte(2147483647).nullable().optional()}); export const resource = z.object({id: z.number().int(), name: z.string().max(255), price: z.string().optional(), count: z.number().int().gte(-2147483648).lte(2147483647).optional()}); export const metricsWorkshopResources = z.object({id: z.number().int(), inventory: baseInventory, inventory_group: baseInventoryGroup, inventory_group_count: z.number().int().gte(-2147483648).lte(2147483647).optional(), price: z.string().optional(), tarif: z.number().int().nullable().optional(), resource: resource.nullable(), extra: z.unknown()}); export const paginatedMetricsWorkshopResourcesList = z.object({count: z.number().int(), next: z.string().nullable().optional(), previous: z.string().nullable().optional(), results: z.array(metricsWorkshopResources)}); 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 }; /** * GET /v1/crm/metrics/workshops/resources/ */ export const getApiV1CrmMetricsWorkshopsResources = async (args: GetApiV1CrmMetricsWorkshopsResourcesArgs, options?: GetApiV1CrmMetricsWorkshopsResourcesOptions) => { const {baseUrl = "https://api.yume.cloud", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.client != null) query.append("client", String(args.client)) if (args.created_at__date__gte != null) query.append("created_at__date__gte", String(args.created_at__date__gte)) if (args.created_at__date__lte != null) query.append("created_at__date__lte", String(args.created_at__date__lte)) if (args.created_by != null) query.append("created_by", String(args.created_by)) if (args.inventory != null) query.append("inventory", String(args.inventory)) if (args.ordering != null) query.append("ordering", String(args.ordering)) if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.search != null) query.append("search", String(args.search)) if (args.status != null) query.append("status", String(args.status)) if (args.type != null) query.append("type", String(args.type)) if (args.worker != null) query.append("worker", String(args.worker)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/crm/metrics/workshops/resources/${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(paginatedMetricsWorkshopResourcesList, await res.json()) };