import {z} from 'zod' export type Unit = 'AMPOULES' | 'APPLICATORS' | 'BOTTLES' | 'BOXES' | 'CAPSULES' | 'CUPS' | 'DOSES' | 'G_PER_ML' | 'GRAMS' | 'IU' | 'IU_PER_ML' | 'OUNCES' | 'FLUID_OUNCES' | 'KG' | 'KITS' | 'LITERS' | 'MCG' | 'MG' | 'MG_PER_ML' | 'ML' | 'MMOL' | 'MICROGRAM_PER_ML' | 'PACKS' | 'PAIRS' | 'PATCHES' | 'PERCENTAGE' | 'PIECES' | 'POUCHES' | 'ROLLS' | 'SACHETS' | 'SHEETS' | 'SPRAYS' | 'STRIPS' | 'SYRINGES' | 'TABLETS' | 'TABLETS_PER_DAY' | 'TESTS' | 'TUBES' | 'UNITS' | 'VIALS' | 'TREATMENTS' | 'SESSIONS' | 'PULSES' | 'JOULES' | 'CENTIMETERS' | 'THREAD_COUNT' | 'INJECTIONS' | 'WRINKLE_UNITS' | 'POUNDS' | 'FEET' | 'INCHES'; export type ItemType = 'ITEM' | 'PRODUCT' | 'MEDICATION' | 'SERVICE' | 'PACKAGE' | 'MEMBERSHIP'; export type ItemTiny = {id?: string | undefined, name: string, brandName?: (string | null) | undefined, description?: (string | null) | undefined, price: number, category?: (string | null) | undefined, unit?: (Unit | null) | undefined, isPhysical?: boolean | undefined, isArchived?: boolean | undefined, internalNotes?: (string | null) | undefined, taxable?: boolean | undefined, sortOrder?: (number | null) | undefined, allowCustomPricing?: boolean | undefined, type?: ItemType | undefined}; export type CommissionDetailInput = {id?: string | undefined, itemId?: (string | null) | undefined, itemCategory?: (string | null) | undefined, itemIsPhysical?: (boolean | null) | undefined, totalSalesAmount?: (number | null) | undefined, commissionStructureId: string, percentage?: (number | null) | undefined, amount?: (number | null) | undefined, deductCost?: boolean | undefined, isArchived?: boolean | undefined, updatedDate?: (string | null) | undefined, createdDate?: (string | null) | undefined, item?: (ItemTiny | null) | undefined}; export type ProviderTiny = {id: string, firstName: string, lastName?: (string | null) | undefined, email?: (string | null) | undefined, createdDate?: (string | null) | undefined}; export type CommissionStructureDetailInput = {id?: string | undefined, name: string, description?: (string | null) | undefined, commissions?: (Array | null) | undefined, providers?: (Array | null) | undefined}; export type ChargeItemDetailInput = {id?: (string | null) | undefined, itemId?: (string | null) | undefined, chargeId: string, name?: (string | null) | undefined, description?: (string | null) | undefined, quantity: number, discountAmount?: (number | null) | undefined, discountPercentage?: (number | null) | undefined, discountReason?: (string | null) | undefined, price: number, soldPackageId?: (string | null) | undefined, bankedQuantity?: (number | null) | undefined, bankedItemId?: (string | null) | undefined, issuedDiscountId?: (string | null) | undefined, soldByProviderId?: (string | null) | undefined, taxAmount?: (number | null) | undefined, pricingId?: (string | null) | undefined, shipmentIds?: (Array | null) | undefined, item?: (ItemTiny | null) | undefined, locationId?: (string | null) | undefined, locationName?: (string | null) | undefined, saleDate?: (string | null) | undefined}; export type EventType = 'APPOINTMENT' | 'SHIFT' | 'BLOCK'; export type LocationTiny = {id: string, isVirtual: boolean}; export type UserType = 'PROVIDER' | 'PATIENT' | 'ASSISTANT'; export type UserTiny = {id: string, firstName?: (string | null) | undefined, lastName?: (string | null) | undefined, phoneNumber?: (string | null) | undefined, email?: (string | null) | undefined, type: UserType, locationId?: (string | null) | undefined}; export type InviteStatus = 'PENDING' | 'ACCEPTED' | 'REJECTED'; export type AttendeeDetailInput = {user: UserTiny, inviteStatus: InviteStatus}; export type EventStatus = 'PENDING' | 'RESERVED' | 'CONFIRMED' | 'CANCELLED' | 'COMPLETED' | 'OVERRIDABLE' | 'NO_SHOW'; export type RecurringEventDetail = {id: string, rrule: string, startDate: string, durationMinutes: number, timezone: string, serviceIds?: (Array | null) | undefined, capacity?: (number | null) | undefined, type: EventType, title: string, attendeeIds?: (Array | null) | undefined, locationId?: (string | null) | undefined, organizerId: string}; export type ServiceTiny = {id: string, duration: number, name: string, locationIds?: (Array | null) | undefined, color: string}; export type EventServiceBookable = {eventId: string, serviceId: string, bookableId: string, start: string, end: string}; export type EventServiceTiny = {service: ServiceTiny, providerId?: (string | null) | undefined, bookables?: (Array | null) | undefined, start?: (string | null) | undefined, end?: (string | null) | undefined, externalId?: (string | null) | undefined, isArchived?: (boolean | null) | undefined}; export type EventIcon = 'BOOKING_FEE_PAID' | 'NEW_PATIENT' | 'SCHEDULED_BY_AI' | 'FORM_COMPLETED' | 'CHECKED_IN'; export type EventTinyInput = {id: string, title: string, start: string, end: string, type: EventType, location?: (LocationTiny | null) | undefined, attendees?: Array | undefined, status: EventStatus, recurringEventId?: (string | null) | undefined, recurringEvent?: (RecurringEventDetail | null) | undefined, eventServices?: Array | undefined, icons?: Array | undefined, capacity?: (number | null) | undefined}; export type PackageStatus = 'USED' | 'ACTIVE' | 'CANCELLED'; export type PackageItemInput = {id?: string | undefined, packageId: string, itemId: string, quantity?: (number | null) | undefined, price: number, item?: (ItemTiny | null) | undefined}; export type PackageInput = {id?: string | undefined, name: string, description?: (string | null) | undefined, isArchived?: boolean | undefined, price: number, internalNotes?: (string | null) | undefined, items?: (Array | null) | undefined, category?: (string | null) | undefined}; export type SoldPackageInput = {id?: string | undefined, packageId: string, patientId: string, chargeItemId: string, status: PackageStatus, package?: (PackageInput | null) | undefined, createdDate: string, updatedDate?: (string | null) | undefined}; export type CommissionPayoutDetailInput = {id?: string | undefined, commissionReportId: string, commissionId: string, providerId: string, amount: number, createdDate?: (string | null) | undefined, provider: ProviderTiny, commission: CommissionDetailInput, chargeItems: Array, events: Array, soldPackages: Array}; export type CommissionReportDetailInput = {commissionStructure: CommissionStructureDetailInput, startDate: string, endDate: string, payouts: Array, totalPayout: number, commissionStructureId: string, creatorId: string, id: string, createdDate?: (string | null) | undefined, updatedDate?: (string | null) | undefined, isArchived?: boolean | undefined}; export type CreateApiInventoryCommissionReportsSaveArgs = {TENANT: string, 'API-KEY': string, body: CommissionReportDetailInput}; export type CreateApiInventoryCommissionReportsSaveOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const unit = z.enum(["AMPOULES", "APPLICATORS", "BOTTLES", "BOXES", "CAPSULES", "CUPS", "DOSES", "G_PER_ML", "GRAMS", "IU", "IU_PER_ML", "OUNCES", "FLUID_OUNCES", "KG", "KITS", "LITERS", "MCG", "MG", "MG_PER_ML", "ML", "MMOL", "MICROGRAM_PER_ML", "PACKS", "PAIRS", "PATCHES", "PERCENTAGE", "PIECES", "POUCHES", "ROLLS", "SACHETS", "SHEETS", "SPRAYS", "STRIPS", "SYRINGES", "TABLETS", "TABLETS_PER_DAY", "TESTS", "TUBES", "UNITS", "VIALS", "TREATMENTS", "SESSIONS", "PULSES", "JOULES", "CENTIMETERS", "THREAD_COUNT", "INJECTIONS", "WRINKLE_UNITS", "POUNDS", "FEET", "INCHES"]); export const itemType = z.enum(["ITEM", "PRODUCT", "MEDICATION", "SERVICE", "PACKAGE", "MEMBERSHIP"]); export const itemTiny = z.object({id: z.string().optional(), name: z.string(), brandName: z.string().nullable().optional(), description: z.string().nullable().optional(), price: z.number().int(), category: z.string().nullable().optional(), unit: unit.nullable().optional(), isPhysical: z.boolean().optional(), isArchived: z.boolean().optional(), internalNotes: z.string().nullable().optional(), taxable: z.boolean().optional(), sortOrder: z.number().int().nullable().optional(), allowCustomPricing: z.boolean().optional(), type: itemType.optional()}); export const commissionDetailOutput = z.object({id: z.string().optional(), itemId: z.string().nullable().optional(), itemCategory: z.string().nullable().optional(), itemIsPhysical: z.boolean().nullable().optional(), totalSalesAmount: z.number().int().nullable().optional(), commissionStructureId: z.string(), percentage: z.number().nullable().optional(), amount: z.number().int().nullable().optional(), deductCost: z.boolean().optional(), isArchived: z.boolean().optional(), updatedDate: z.string().nullable().optional(), createdDate: z.string().nullable().optional(), item: itemTiny.nullable().optional()}); export const providerTiny = z.object({id: z.string(), firstName: z.string(), lastName: z.string().nullable().optional(), email: z.string().nullable().optional(), createdDate: z.string().nullable().optional()}); export const commissionStructureDetailOutput = z.object({id: z.string().optional(), name: z.string(), description: z.string().nullable().optional(), commissions: z.array(commissionDetailOutput).nullable().optional(), providers: z.array(providerTiny).nullable().optional()}); export const chargeItemDetailOutput = z.object({id: z.string().nullable().optional(), itemId: z.string().nullable().optional(), chargeId: z.string(), name: z.string().nullable().optional(), description: z.string().nullable().optional(), quantity: z.number().int(), discountAmount: z.number().int().nullable().optional(), discountPercentage: z.number().nullable().optional(), discountReason: z.string().nullable().optional(), price: z.number().int(), soldPackageId: z.string().nullable().optional(), bankedQuantity: z.number().int().nullable().optional(), bankedItemId: z.string().nullable().optional(), issuedDiscountId: z.string().nullable().optional(), soldByProviderId: z.string().nullable().optional(), taxAmount: z.number().int().nullable().optional(), pricingId: z.string().nullable().optional(), shipmentIds: z.array(z.string()).nullable().optional(), item: itemTiny.nullable().optional(), locationId: z.string().nullable().optional(), locationName: z.string().nullable().optional(), saleDate: z.string().nullable().optional()}); export const eventType = z.enum(["APPOINTMENT", "SHIFT", "BLOCK"]); export const locationTiny = z.object({id: z.string(), isVirtual: z.boolean()}); export const userType = z.enum(["PROVIDER", "PATIENT", "ASSISTANT"]); export const userTiny = z.object({id: z.string(), firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional(), phoneNumber: z.string().nullable().optional(), email: z.string().nullable().optional(), type: userType, locationId: z.string().nullable().optional()}); export const inviteStatus = z.enum(["PENDING", "ACCEPTED", "REJECTED"]); export const attendeeDetailOutput = z.object({user: userTiny, inviteStatus: inviteStatus}); export const eventStatus = z.enum(["PENDING", "RESERVED", "CONFIRMED", "CANCELLED", "COMPLETED", "OVERRIDABLE", "NO_SHOW"]); export const recurringEventDetail = z.object({id: z.string(), rrule: z.string(), startDate: z.string(), durationMinutes: z.number().int(), timezone: z.string(), serviceIds: z.array(z.string()).nullable().optional(), capacity: z.number().int().nullable().optional(), type: eventType, title: z.string(), attendeeIds: z.array(z.string()).nullable().optional(), locationId: z.string().nullable().optional(), organizerId: z.string()}); export const serviceTiny = z.object({id: z.string(), duration: z.number().int(), name: z.string(), locationIds: z.array(z.string()).nullable().optional(), color: z.string()}); export const eventServiceBookable = z.object({eventId: z.string(), serviceId: z.string(), bookableId: z.string(), start: z.string(), end: z.string()}); export const eventServiceTiny = z.object({service: serviceTiny, providerId: z.string().nullable().optional(), bookables: z.array(eventServiceBookable).nullable().optional(), start: z.string().nullable().optional(), end: z.string().nullable().optional(), externalId: z.string().nullable().optional(), isArchived: z.boolean().nullable().optional()}); export const eventIcon = z.enum(["BOOKING_FEE_PAID", "NEW_PATIENT", "SCHEDULED_BY_AI", "FORM_COMPLETED", "CHECKED_IN"]); export const eventTinyOutput = z.object({id: z.string(), title: z.string(), start: z.string(), end: z.string(), type: eventType, location: locationTiny.nullable().optional(), attendees: z.array(attendeeDetailOutput).optional(), status: eventStatus, recurringEventId: z.string().nullable().optional(), recurringEvent: recurringEventDetail.nullable().optional(), eventServices: z.array(eventServiceTiny).optional(), icons: z.array(eventIcon).optional(), capacity: z.number().int().nullable().optional()}); export const packageStatus = z.enum(["USED", "ACTIVE", "CANCELLED"]); export const packageItemOutput = z.object({id: z.string().optional(), packageId: z.string(), itemId: z.string(), quantity: z.number().int().nullable().optional(), price: z.number().int(), item: itemTiny.nullable().optional()}); export const packageOutput = z.object({id: z.string().optional(), name: z.string(), description: z.string().nullable().optional(), isArchived: z.boolean().optional(), price: z.number().int(), internalNotes: z.string().nullable().optional(), items: z.array(packageItemOutput).nullable().optional(), category: z.string().nullable().optional()}); export const soldPackageOutput = z.object({id: z.string().optional(), packageId: z.string(), patientId: z.string(), chargeItemId: z.string(), status: packageStatus, package: packageOutput.nullable().optional(), createdDate: z.string(), updatedDate: z.string().nullable().optional()}); export const commissionPayoutDetailOutput = z.object({id: z.string().optional(), commissionReportId: z.string(), commissionId: z.string(), providerId: z.string(), amount: z.number().int(), createdDate: z.string().nullable().optional(), provider: providerTiny, commission: commissionDetailOutput, chargeItems: z.array(chargeItemDetailOutput), events: z.array(eventTinyOutput), soldPackages: z.array(soldPackageOutput)}); export const commissionReportDetailOutput = z.object({commissionStructure: commissionStructureDetailOutput, startDate: z.string(), endDate: z.string(), payouts: z.array(commissionPayoutDetailOutput), totalPayout: z.number().int(), commissionStructureId: z.string(), creatorId: z.string(), id: z.string(), createdDate: z.string().nullable().optional(), updatedDate: z.string().nullable().optional(), isArchived: z.boolean().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 }; /** * Save Commission Report * * POST /inventory/commission-reports/save */ export const createApiInventoryCommissionReportsSave = async (args: CreateApiInventoryCommissionReportsSaveArgs, options: CreateApiInventoryCommissionReportsSaveOptions) => { 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") if (args.TENANT != null) headers.set("TENANT", String(args.TENANT)) if (args['API-KEY'] != null) headers.set("API-KEY", String(args['API-KEY'])) const url = `${baseUrl.replace(/\/+$/, '')}/inventory/commission-reports/save${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(commissionReportDetailOutput, await res.json()) };