import {z} from 'zod' export type GetApiApiReportsFinancialLucrosCarrosDetailArgs = {mes?: Array | undefined, ano: number, ponto_venda_id?: Array | undefined, 'x-api-token'?: (string | null) | undefined}; export type GetApiApiReportsFinancialLucrosCarrosDetailOptions = {baseUrl: string, APIToken?: string | undefined, OriginVerify?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiReportsFinancialLucrosCarrosDetailResponse = z.unknown(); 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 Lucros Carros Detail * * GET /api/reports/financial/lucros-carros/detail */ export const getApiApiReportsFinancialLucrosCarrosDetail = async (args: GetApiApiReportsFinancialLucrosCarrosDetailArgs, options: GetApiApiReportsFinancialLucrosCarrosDetailOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIToken, OriginVerify} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.mes ?? []) query.append("mes", String(item)) if (args.ano != null) query.append("ano", String(args.ano)) for (const item of args.ponto_venda_id ?? []) query.append("ponto_venda_id", String(item)) if (args['x-api-token'] != null) headers.set("x-api-token", String(args['x-api-token'])) if (APIToken !== undefined) headers.set("x-api-token", APIToken) if (OriginVerify !== undefined) headers.set("x-origin-verify", OriginVerify) const url = `${baseUrl.replace(/\/+$/, '')}/api/reports/financial/lucros-carros/detail${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(getApiApiReportsFinancialLucrosCarrosDetailResponse, await res.json()) };