import { z } from "zod/v4"; import { ResourceInputSchema, ResourceSpecificationSchema } from "../../inventory"; import { OperatingSystemIdentitySchema } from "../../operating-system-identity"; export const ResourcePurposeSchema = z.enum(["software-installation", "application-configuration"]); const identity = { id: z.uuid(), templateId: z.uuid(), name: z.string().min(1).max(100), active: z.boolean(), }; export const ApplicationReferenceSchema = z.discriminatedUnion("scope", [ z.strictObject({ ...identity, kind: z.literal("application"), scope: z.literal("global"), companyId: z.null(), }), z.strictObject({ ...identity, kind: z.literal("application"), scope: z.literal("company"), companyId: z.uuid(), }), ]); export const LocalOsReferenceSchema = z.strictObject({ ...identity, kind: z.literal("os"), scope: z.literal("company"), companyId: z.uuid(), }); export const GlobalOperatingSystemReferenceSchema = z.strictObject({ ...identity, ...OperatingSystemIdentitySchema.shape, kind: z.literal("os"), scope: z.literal("global"), companyId: z.null(), href: z.string().startsWith("/catalogs/global-operating-systems/"), }); export const GlobalOperatingSystemDetailSchema = GlobalOperatingSystemReferenceSchema.extend({ url: z.string().nullable(), description: z.string().nullable(), }); export type GlobalOperatingSystemReference = z.infer; export type GlobalOperatingSystemDetail = z.infer; export const SoftwareReferenceSchema = z.union([ GlobalOperatingSystemReferenceSchema, ApplicationReferenceSchema, LocalOsReferenceSchema, ]); export const CompanyApplicationSummarySchema = z.union([ ApplicationReferenceSchema.options[0].extend({ provider: z.string().nullable() }), ApplicationReferenceSchema.options[1].extend({ provider: z.string().nullable() }), ]); export type CompanyApplicationSummary = z.infer; export const ApplicationCandidateSchema = z.union([ ApplicationReferenceSchema.options[0].extend({ active: z.literal(true), provider: z.string().nullable(), }), ApplicationReferenceSchema.options[1].extend({ active: z.literal(true), provider: z.string().nullable(), }), ]); export const ResourceCandidateSchema = z.union([ GlobalOperatingSystemReferenceSchema.extend({ active: z.literal(true) }), ApplicationCandidateSchema, LocalOsReferenceSchema.extend({ active: z.literal(true), provider: z.string().nullable() }), ]); export const GlobalApplicationSummarySchema = z.strictObject({ ...identity, kind: z.literal("application"), scope: z.literal("global"), companyId: z.null(), provider: z.string().nullable(), }); export const GlobalApplicationDetailSchema = GlobalApplicationSummarySchema.extend({ url: z.string().nullable(), description: z.string().nullable(), }); export const GlobalResourceAdminSchema = z.strictObject({ revisionId: z.uuid(), id: z.uuid(), scope: z.literal("global"), companyId: z.null(), values: ResourceInputSchema.omit({ integration: true }), specification: ResourceSpecificationSchema, }); export type ResourcePurpose = z.infer; export type SoftwareReference = z.infer; export type ResourceCandidate = z.infer; export type GlobalApplicationSummary = z.infer; export type GlobalApplicationDetail = z.infer;