import {z} from 'zod' export type CreateApiV1DocumentsDocumentIdAssignmentsEstimateCostArgs = {documentId: string, body: {method?: ('virtual' | 'collect') | undefined, signers?: (Array<{verification_method?: ('Email' | 'Whatsapp' | 'DigitalCertificate' | 'IdDocumentFaceMatchBasic') | undefined, notification_methods?: (Array<'Email' | 'Whatsapp'>) | undefined}>) | undefined, entries?: Array> | undefined}}; export type CreateApiV1DocumentsDocumentIdAssignmentsEstimateCostOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const costEstimateBreakdownItem = z.object({code: z.string().optional(), name: z.string().optional(), cost: z.number().optional(), quantity: z.number().int().optional(), unit_cost: z.number().optional()}); export const costEstimate = z.object({documents: z.number().int().optional(), credits: z.number().optional(), needs_extra_document: z.boolean().optional(), extra_document_cost: z.number().optional(), total_credits: z.number().optional(), breakdown: z.array(costEstimateBreakdownItem).optional(), document_balance: z.number().optional(), credit_balance: z.number().optional(), has_sufficient_resources: z.boolean().optional(), blocking_reason: z.enum(["PendingPayment", "InsufficientDocuments", "InsufficientCredits"]).nullable().optional(), message: z.string().nullable().optional()}); export const createApiV1DocumentsDocumentIdAssignmentsEstimateCostResponse = z.object({status: z.number().int().optional(), message: z.string().optional(), data: costEstimate.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 }; /** * Estimate assignment cost * * POST /v1/documents/{documentId}/assignments/estimate-cost * * Also accepts auth: apiKeyAuth */ export const createApiV1DocumentsDocumentIdAssignmentsEstimateCost = async (args: CreateApiV1DocumentsDocumentIdAssignmentsEstimateCostArgs, options?: CreateApiV1DocumentsDocumentIdAssignmentsEstimateCostOptions) => { const {baseUrl = "https://api.assinafy.com.br", 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/documents/${encodeURIComponent(String(args.documentId))}/assignments/estimate-cost${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiV1DocumentsDocumentIdAssignmentsEstimateCostResponse, await res.json()) };