import {z} from 'zod' export type DecisionAnswer = {Id?: string | undefined, Answer?: string | undefined}; export type ServiceChannelServicesMessagingWorkordersGetWorkOrderPropertiesRequest = {AreaName?: string | undefined, ProblemType?: string | undefined, EquipmentType?: string | undefined, ProblemCode?: string | undefined, LocationId?: number | undefined, SetupId?: number | undefined, AssetId?: number | undefined, DecisionAnswers?: Array | undefined, CorrelationId?: string | undefined}; export type CreateApiSubscribersCurrentServicerequestOverridesPropsArgs = {body: ServiceChannelServicesMessagingWorkordersGetWorkOrderPropertiesRequest}; export type CreateApiSubscribersCurrentServicerequestOverridesPropsOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const serviceChannelApiModelWorkordersOverridePropertiesServiceProvider = z.object({Id: z.number().int().optional(), Name: z.string().optional(), Rank: z.number().int().optional(), Default: z.boolean().optional(), DoNotDispatch: z.boolean().optional(), Pilot: z.boolean().optional(), IsInternal: z.boolean().optional()}); export const serviceChannelApiModelWorkordersOverridePropertiesTrade = z.object({Id: z.number().int().optional(), Name: z.string().optional()}); export const serviceChannelApiModelWorkordersOverridePropertiesCategory = z.object({Id: z.number().int().optional(), Name: z.string().optional()}); export const serviceChannelApiModelWorkordersOverridePropertiesAnomaly = z.object({TradeAnomalous: z.boolean().optional(), TradeScore: z.number().optional(), NTEAnomalous: z.boolean().optional(), NTEScore: z.number().optional(), FirstTimeFixAnomalous: z.boolean().optional(), FirstTimeFixScore: z.number().optional(), Top1PrimaryTrade: z.string().optional(), InvoiceTotalWithoutProposal25: z.number().optional(), InvoiceTotalWithoutProposalMedian: z.number().optional(), InvoiceTotalWithProposal75: z.number().optional(), IsAnomaly: z.boolean().optional()}); export const serviceChannelApiModelDashboardAssetsAsset = z.object({Id: z.number().int().optional(), TagID: z.string().optional(), Manufacturer: z.string().optional(), ModelNo: z.string().optional(), SerialNo: z.string().optional(), Location: z.string().optional(), WarrantyExpirationDate: z.string().optional(), WarrantyCategory: z.string().optional(), Nte: z.number().optional(), WarrantyPriority: z.string().optional(), WarrantyNTEHidden: z.boolean().optional(), WarrantyNotExpired: z.boolean().optional(), Type: z.string().optional(), AssetTag: z.string().optional(), Description: z.string().optional(), StoreId: z.string().optional()}); export const serviceChannelServicesMessagingDashboardContractServiceContractServiceRate = z.object({RateId: z.number().int().optional(), RateName: z.string().optional(), ContractedServiceId: z.number().int().optional(), ContractedServiceName: z.string().optional(), TradeId: z.number().int().optional(), CategoryId: z.number().int().optional(), RateType: z.string().optional(), BaseAmount: z.number().optional(), VariableAmount: z.number().optional(), NteAmount: z.number().optional(), CurrencyId: z.number().int().optional(), CurrencyAlphabeticCode: z.string().optional()}); export const serviceChannelServicesRequestHandlersWorkOrdersGetWorkOrderPropertiesWithOverridesResponse = z.object({Providers: z.array(serviceChannelApiModelWorkordersOverridePropertiesServiceProvider).optional(), Trade: serviceChannelApiModelWorkordersOverridePropertiesTrade.optional(), Category: serviceChannelApiModelWorkordersOverridePropertiesCategory.optional(), Priority: z.string().optional(), Nte: z.number().optional(), NteCurrencyId: z.number().int().optional(), WoLabels: z.array(z.string()).optional(), AssetAssociatedWithTrade: z.boolean().optional(), LeaseNote: z.string().optional(), ProviderFoundType: z.enum(["Found", "NotFound", "DoNotDispatch", "TradeExcluded"]).optional(), EtcMinutes: z.number().int().optional(), Anomaly: serviceChannelApiModelWorkordersOverridePropertiesAnomaly.optional(), IsAnomalyProviderOverwritten: z.boolean().optional(), EtcMinutesFromIssueChoice: z.number().int().optional(), Asset: serviceChannelApiModelDashboardAssetsAsset.optional(), ContractServiceRate: serviceChannelServicesMessagingDashboardContractServiceContractServiceRate.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 }; /** * Get WorkOrder properties with overrides * * POST /subscribers/current/servicerequest/overrides/props */ export const createApiSubscribersCurrentServicerequestOverridesProps = async (args: CreateApiSubscribersCurrentServicerequestOverridesPropsArgs, options?: CreateApiSubscribersCurrentServicerequestOverridesPropsOptions) => { const {baseUrl = "https://sb2api.servicechannel.com/v3", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/subscribers/current/servicerequest/overrides/props${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(serviceChannelServicesRequestHandlersWorkOrdersGetWorkOrderPropertiesWithOverridesResponse, await res.json()) };