import {z} from 'zod' export type CustomerProfileManualUpdate = {customer_name?: (string | null) | undefined, phone_number?: (string | null) | undefined, country?: (string | null) | undefined}; export type UpdateApiApiV1ReportAiCustomerProfilesCustomerProfileIdArgs = {customer_profile_id: string, body: CustomerProfileManualUpdate}; export type UpdateApiApiV1ReportAiCustomerProfilesCustomerProfileIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const customerIdentityKind = z.enum(["person", "shared_inbox", "unclassified", "stay_guest"]); export const sourceBadgeRead = z.object({source_key: z.string(), label: z.string(), badge_hue: z.string(), external_id: z.string().nullable().optional(), first_seen_at: z.string(), last_seen_at: z.string()}); export const attentionFlag = z.object({kind: z.enum(["open_duplicate", "field_conflict", "relay_identity", "no_source"]), detail: z.string()}); export const customerProfileRead = z.object({id: z.string(), tenant_id: z.string(), customer_email: z.string().nullable(), customer_name: z.string().nullable(), phone_number: z.string().nullable(), total_investigations: z.number().int(), complaints_count: z.number().int(), last_sentiment: z.string().nullable(), total_revenue_cents: z.number().int().nullable(), average_booking_value_cents: z.number().int().nullable(), loyalty_tier: z.string().nullable(), country: z.string().nullable().optional(), identity_kind: customerIdentityKind.optional(), requires_attention: z.boolean().optional(), attention_reason: z.string().nullable().optional(), business_id: z.string().nullable().optional(), first_seen_at: z.string(), last_seen_at: z.string(), sources: z.array(sourceBadgeRead).optional(), attention: z.array(attentionFlag).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 Customer Profile * * PUT /api/v1/report-ai/customer-profiles/{customer_profile_id} */ export const updateApiApiV1ReportAiCustomerProfilesCustomerProfileId = async (args: UpdateApiApiV1ReportAiCustomerProfilesCustomerProfileIdArgs, options: UpdateApiApiV1ReportAiCustomerProfilesCustomerProfileIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/report-ai/customer-profiles/${encodeURIComponent(String(args.customer_profile_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(customerProfileRead, await res.json()) };