import {z} from 'zod' export type GetApiDealershipsDealershipIdTasksArgs = {dealershipId: number, assigned_to?: number | undefined, status?: ('pending' | 'in_progress' | 'completed' | 'cancelled') | undefined, priority?: ('low' | 'medium' | 'high') | undefined, due_date_from?: string | undefined, due_date_to?: string | undefined, trashed?: ('with' | 'only' | 'without') | undefined, embed?: string | undefined, page?: number | undefined, per_page?: number | undefined, sort?: string | undefined}; export type GetApiDealershipsDealershipIdTasksOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const activity = z.object({id: z.number().int(), assigned_to: z.number().int().nullable().optional(), shopper_id: z.number().int().nullable().optional(), task_id: z.number().int().nullable().optional(), type: z.enum(["call", "email", "meeting", "note", "task"]), type_id: z.number().int().nullable().optional(), title: z.string(), description: z.string().nullable().optional(), notes: z.string().nullable().optional(), status: z.string().nullable().optional(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional(), shopper: z.record(z.string(), z.unknown()).nullable().optional()}); export const taskNote = z.object({id: z.number().int(), task_id: z.number().int(), content: z.string(), profile_id: z.number().int().nullable().optional(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional(), profile: z.record(z.string(), z.unknown()).nullable().optional()}); export const task = z.object({id: z.number().int(), shopper_id: z.number().int().nullable().optional(), created_by: z.number().int().nullable().optional(), assigned_to: z.number().int().nullable().optional(), type: z.string(), title: z.string().max(255), description: z.string().nullable().optional(), priority: z.enum(["low", "medium", "high"]).nullable().optional(), status: z.enum(["pending", "in_progress", "completed", "cancelled"]), department: z.string().nullable().optional(), due_date: z.string().nullable().optional(), created_at: z.string(), updated_at: z.string(), deleted_at: z.string().nullable().optional(), activities: z.array(activity).optional(), notes: z.array(taskNote).optional(), shopper: z.record(z.string(), z.unknown()).nullable().optional()}); export const pagination = z.object({page: z.number().int().gte(1), per_page: z.number().int().gte(1).lte(100), total: z.number().int().gte(0), total_pages: z.number().int().gte(0)}); export const tasksResponse = z.object({data: z.array(task), pagination: pagination}); 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 }; /** * List tasks * * GET /dealerships/{dealershipId}/tasks */ export const getApiDealershipsDealershipIdTasks = async (args: GetApiDealershipsDealershipIdTasksArgs, options?: GetApiDealershipsDealershipIdTasksOptions) => { const {baseUrl = "https://api.fullpath.com/consent-management", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.assigned_to != null) query.append("assigned_to", String(args.assigned_to)) if (args.status != null) query.append("status", String(args.status)) if (args.priority != null) query.append("priority", String(args.priority)) if (args.due_date_from != null) query.append("due_date_from", String(args.due_date_from)) if (args.due_date_to != null) query.append("due_date_to", String(args.due_date_to)) if (args.trashed != null) query.append("trashed", String(args.trashed)) if (args.embed != null) query.append("embed", String(args.embed)) if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.sort != null) query.append("sort", String(args.sort)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/dealerships/${encodeURIComponent(String(args.dealershipId))}/tasks${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(tasksResponse, await res.json()) };