import {z} from 'zod' export type GetApiWorkordersWorkOrderIdChecklistsResponsesArgs = {workOrderId: number, getAll?: boolean | undefined}; export type GetApiWorkordersWorkOrderIdChecklistsResponsesOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const serviceChannelServicesWebApiModelsResponseChecklistsChecklistResponsesChecklistPictureResponse = z.object({Id: z.number().int().optional(), CheckListResponseId: z.number().int().optional(), DocumentName: z.string().optional(), DocumentPath: z.string().optional(), ThumbnailPath: z.string().optional(), HasThumbnail: z.boolean().optional(), UpdatedBy: z.number().int().optional()}); export const serviceChannelServicesWebApiModelsResponseChecklistsChecklistResponsesChecklistQuestionOptionResponse = z.object({Id: z.number().int().optional(), Answer: z.string().optional(), Sequence: z.number().int().optional(), IsConditionalFollowUp: z.boolean().optional(), ResponseResultInFailure: z.boolean().optional()}); export const serviceChannelServicesWebApiModelsResponseChecklistsChecklistResponsesCheckListAcknowledgeUrlResponse = z.object({Url: z.string().optional(), Required: z.boolean().optional()}); export const serviceChannelServicesWebApiModelsResponseChecklistsChecklistResponsesChecklistQuestionNumericType = z.object({Id: z.number().int().optional(), Type: z.enum(["LessThan", "MoreThan", "InBetween"]).optional(), SingleValue: z.number().int().optional(), MinValue: z.number().int().optional(), MaxValue: z.number().int().optional()}); export const serviceChannelServicesWebApiModelsResponseChecklistsChecklistResponsesCheckListDetailQuestionsExtendedResponse = z.object({CheckListCreatedDate: z.string().optional(), CheckListName: z.string().optional(), Id: z.number().int().optional(), CheckListId: z.number().int().optional(), Question: z.string().optional(), ShortDescription: z.string().optional(), AnswerRequired: z.boolean().optional(), PictureFlag: z.enum(["Optional", "No", "Required"]).optional(), Sequence: z.number().int().optional(), QuestionType: z.enum(["CheckBox", "RadioButton", "TextEntry", "TriState", "NumericInput"]).optional(), CheckListQuestionOptions: z.array(serviceChannelServicesWebApiModelsResponseChecklistsChecklistResponsesChecklistQuestionOptionResponse).optional(), AnswerCanPersist: z.boolean().optional(), CheckListTimingType: z.enum(["CheckIn", "CheckOut"]).optional(), AcknowledgeUrl: serviceChannelServicesWebApiModelsResponseChecklistsChecklistResponsesCheckListAcknowledgeUrlResponse.optional(), AllowMultiSelect: z.boolean().optional(), ChecklistFailure: z.boolean().optional(), AssetTypeIds: z.array(z.number().int()).optional(), ChecklistQuestionNumericType: serviceChannelServicesWebApiModelsResponseChecklistsChecklistResponsesChecklistQuestionNumericType.optional()}); export const serviceChannelServicesWebApiModelsResponseChecklistsChecklistResponsesCheckListResponseExtended = z.object({Pictures: z.array(serviceChannelServicesWebApiModelsResponseChecklistsChecklistResponsesChecklistPictureResponse).optional(), Question: serviceChannelServicesWebApiModelsResponseChecklistsChecklistResponsesCheckListDetailQuestionsExtendedResponse.optional(), QuestionOptions: z.array(serviceChannelServicesWebApiModelsResponseChecklistsChecklistResponsesChecklistQuestionOptionResponse).optional(), QuestionOption: serviceChannelServicesWebApiModelsResponseChecklistsChecklistResponsesChecklistQuestionOptionResponse.optional(), IsCurrentChecklist: z.boolean().optional(), IsFrequencyChecklist: z.boolean().optional(), CreatedBy: z.number().int().optional(), AssetId: z.number().int().optional(), Id: z.number().int().optional(), Answer: z.string().optional(), FreeTextAnswer: z.string().optional(), EntityId: z.number().int().optional(), EntityTypeId: z.number().int().optional(), Attempt: z.number().int().optional(), ProviderId: z.number().int().optional(), TechnicianId: z.number().int().optional(), UpdatedDate: z.string().optional(), UpdatedDateStr: z.string().optional(), UpdatedDateDto: z.string().optional(), IsPassed: z.boolean().optional(), LinkedWorkOrderId: z.number().int().optional()}); export const serviceChannelServicesWebApiModelsResponseChecklistsChecklistResponsesGetResponsesByWorkOrderResponse = z.object({Responses: z.array(serviceChannelServicesWebApiModelsResponseChecklistsChecklistResponsesCheckListResponseExtended).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 checklist responses for a work order * * GET /workorders/{workOrderId}/checklists-responses */ export const getApiWorkordersWorkOrderIdChecklistsResponses = async (args: GetApiWorkordersWorkOrderIdChecklistsResponsesArgs, options?: GetApiWorkordersWorkOrderIdChecklistsResponsesOptions) => { const {baseUrl = "https://sb2api.servicechannel.com/v3", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.getAll != null) query.append("getAll", String(args.getAll)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/workorders/${encodeURIComponent(String(args.workOrderId))}/checklists-responses${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(serviceChannelServicesWebApiModelsResponseChecklistsChecklistResponsesGetResponsesByWorkOrderResponse, await res.json()) };