import type { z } from 'zod'
import { OrganizationModelBrandingSchema } from './domains/branding'
import { SalesPipelineSchema, SalesStageSchema } from './domains/sales'
import { ProjectsDomainStateSchema } from './domains/projects'
import { NodeIdPathSchema, NodeIdStringSchema } from './domains/systems'
import { ProspectingBuildTemplateSchema, ProspectingLifecycleStageSchema } from './domains/prospecting'
import {
  NavigationGroupSchema,
  OrganizationModelNavigationSchema,
  SidebarNavigationSchema,
  SidebarNodeSchema,
  SidebarSectionSchema,
  SidebarSurfaceTargetsSchema,
  SurfaceDefinitionSchema,
  TopbarActionNodeSchema,
  TopbarSectionSchema
} from './domains/navigation'
import { TechStackEntrySchema } from './domains/shared'
import { StatusesDomainSchema, StatusEntrySchema, StatusSemanticClassSchema } from './domains/statuses'
import { CustomersDomainSchema, CustomerSegmentSchema, FirmographicsSchema } from './domains/customers'
import { OfferingsDomainSchema, ProductSchema, PricingModelSchema } from './domains/offerings'
import {
  AgentRoleHolderSchema,
  HumanRoleHolderSchema,
  RoleHolderSchema,
  RoleIdSchema,
  RolesDomainSchema,
  RoleSchema,
  TeamRoleHolderSchema
} from './domains/roles'
import { GoalsDomainSchema, ObjectiveSchema, KeyResultSchema } from './domains/goals'
import {
  KnowledgeDomainSchema,
  KnowledgeLinkSchema,
  KnowledgeTargetKindSchema,
  KnowledgeTargetRefSchema,
  OrgKnowledgeKindSchema,
  OrgKnowledgeNodeSchema
} from './domains/knowledge'
import {
  SystemEntrySchema,
  SystemInterfaceKeySchema,
  SystemInterfaceLifecycleSchema,
  SystemInterfaceReadinessProfileSchema,
  SystemInterfaceRefSchema,
  SystemApiInterfaceSchema,
  SystemConfigSchema,
  SystemIdSchema,
  SystemKindSchema,
  SystemLifecycleSchema,
  SystemPathSchema,
  SystemStatusSchema,
  SystemsDomainSchema
} from './domains/systems'
import {
  AgentKindSchema,
  AgentResourceEntrySchema,
  CodeReferenceRoleSchema,
  CodeReferenceSchema,
  ContractRefSchema,
  EventDescriptorSchema,
  EventEmissionDescriptorSchema,
  EventIdSchema,
  IntegrationResourceEntrySchema,
  ResourceEntrySchema,
  ResourceGovernanceStatusSchema,
  ResourceIdSchema,
  ResourceKindSchema,
  ResourceOntologyBindingSchema,
  ResourcesDomainSchema,
  ScriptResourceEntrySchema,
  ScriptResourceLanguageSchema,
  ScriptResourceSourceSchema,
  WorkflowResourceEntrySchema,
  type ParsedContractRef,
  type ResourceOntologyBindingContract
} from './domains/resources'
import {
  OmTopologyDomainSchema,
  OmTopologyMetadataSchema,
  OmTopologyNodeKindSchema,
  OmTopologyNodeRefSchema,
  OmTopologyRelationshipKindSchema,
  OmTopologyRelationshipSchema,
  OmTopologySystemInterfaceGrantMetadataSchema,
  OmTopologySystemInterfaceGrantSchema
} from './domains/topology'
import {
  ActionsDomainSchema,
  ActionIdSchema,
  ActionInvocationKindSchema,
  ActionInvocationSchema,
  ActionRefSchema,
  ActionSchema,
  ActionScopeSchema
} from './domains/actions'
import { EntitiesDomainSchema, EntityIdSchema, EntityLinkSchema, EntitySchema } from './domains/entities'
import {
  PoliciesDomainSchema,
  PolicyEffectSchema,
  PolicyApplicabilitySchema,
  PolicyIdSchema,
  PolicyPredicateSchema,
  PolicySchema,
  PolicyTriggerSchema
} from './domains/policies'
import { OrganizationModelIconTokenSchema, OrganizationModelBuiltinIconTokenSchema } from './icons'
import { OntologyScopeSchema } from './ontology'
import {
  OrganizationModelDomainKeySchema,
  OrganizationModelDomainMetadataByDomainSchema,
  OrganizationModelDomainMetadataSchema,
  OrganizationModelSchema,
  ClientProfileBrandingSchema,
  ClientProfileIdentitySchema,
  ClientProfileLinksSchema,
  ClientProfilePromptsSchema,
  ClientProfileSchema,
  ClientProfileSourceSchema,
  ClientProfileStatusSchema,
  ClientProfileWorkspaceSchema,
  ClientProfilesDomainSchema
} from './schema'

export type OrganizationModel = z.infer<typeof OrganizationModelSchema>
export type OrganizationModelDomainKey = z.infer<typeof OrganizationModelDomainKeySchema>
export type OrganizationModelDomainMetadata = z.infer<typeof OrganizationModelDomainMetadataSchema>
export type OrganizationModelDomainMetadataByDomain = z.infer<typeof OrganizationModelDomainMetadataByDomainSchema>
export type OrganizationModelBranding = z.infer<typeof OrganizationModelBrandingSchema>
export type ClientProfile = z.infer<typeof ClientProfileSchema>
export type ClientProfileBranding = z.infer<typeof ClientProfileBrandingSchema>
export type ClientProfileIdentity = z.infer<typeof ClientProfileIdentitySchema>
export type ClientProfileLinks = z.infer<typeof ClientProfileLinksSchema>
export type ClientProfilePrompts = z.infer<typeof ClientProfilePromptsSchema>
export type ClientProfileSource = z.infer<typeof ClientProfileSourceSchema>
export type ClientProfileStatus = z.infer<typeof ClientProfileStatusSchema>
export type ClientProfileWorkspace = z.infer<typeof ClientProfileWorkspaceSchema>
export type OrganizationModelClients = z.infer<typeof ClientProfilesDomainSchema>
// Phase 4: OrganizationModelSales, OrganizationModelProspecting, OrganizationModelProjects,
// OrganizationModelNavigation removed — compound domain top-level fields deleted per D8/D1.
// Retained as local aliases for content-kind payload shapes used in migration-helpers:
export type SalesPipeline = z.infer<typeof SalesPipelineSchema>
export type SalesStage = z.infer<typeof SalesStageSchema>
export type ProspectingBuildTemplate = z.infer<typeof ProspectingBuildTemplateSchema>
export type ProspectingLifecycleStage = z.infer<typeof ProspectingLifecycleStageSchema>
export type ProjectsDomainState = z.infer<typeof ProjectsDomainStateSchema>
export type NodeIdPath = z.infer<typeof NodeIdPathSchema>
export type NodeIdString = z.infer<typeof NodeIdStringSchema>
export type OrganizationModelSurface = z.infer<typeof SurfaceDefinitionSchema>
export type OrganizationModelNavigationGroup = z.infer<typeof NavigationGroupSchema>
export type OrganizationModelNavigation = z.infer<typeof OrganizationModelNavigationSchema>
export type OrganizationModelSidebar = z.infer<typeof SidebarNavigationSchema>
export type OrganizationModelSidebarSection = z.infer<typeof SidebarSectionSchema>
export type OrganizationModelSidebarNode = z.infer<typeof SidebarNodeSchema>
export type OrganizationModelSidebarSurfaceTargets = z.infer<typeof SidebarSurfaceTargetsSchema>
export type OrganizationModelSidebarSurfaceNode = Extract<OrganizationModelSidebarNode, { type: 'surface' }>
export type OrganizationModelSidebarGroupNode = Extract<OrganizationModelSidebarNode, { type: 'group' }>
export type OrganizationModelTopbarActionNode = z.infer<typeof TopbarActionNodeSchema>
export type OrganizationModelTopbarSection = z.infer<typeof TopbarSectionSchema>
export type OrganizationModelTechStackEntry = z.infer<typeof TechStackEntrySchema>
export type OrganizationModelStatuses = z.infer<typeof StatusesDomainSchema>
export type OrganizationModelStatusEntry = z.infer<typeof StatusEntrySchema>
export type OrganizationModelStatusSemanticClass = z.infer<typeof StatusSemanticClassSchema>
export type OrganizationModelCustomers = z.infer<typeof CustomersDomainSchema>
export type OrganizationModelCustomerSegment = z.infer<typeof CustomerSegmentSchema>
export type OrganizationModelCustomerFirmographics = z.infer<typeof FirmographicsSchema>
export type OrganizationModelOfferings = z.infer<typeof OfferingsDomainSchema>
export type OrganizationModelProduct = z.infer<typeof ProductSchema>
export type OrganizationModelPricingModel = z.infer<typeof PricingModelSchema>
export type OrganizationModelRoles = z.infer<typeof RolesDomainSchema>
export type OrganizationModelRole = z.infer<typeof RoleSchema>
export type OrganizationModelRoleId = z.infer<typeof RoleIdSchema>
export type OrganizationModelRoleHolder = z.infer<typeof RoleHolderSchema>
export type OrganizationModelHumanRoleHolder = z.infer<typeof HumanRoleHolderSchema>
export type OrganizationModelAgentRoleHolder = z.infer<typeof AgentRoleHolderSchema>
export type OrganizationModelTeamRoleHolder = z.infer<typeof TeamRoleHolderSchema>
export type OrganizationModelGoals = z.infer<typeof GoalsDomainSchema>
export type OrganizationModelObjective = z.infer<typeof ObjectiveSchema>
export type OrganizationModelKeyResult = z.infer<typeof KeyResultSchema>
export type OrganizationModelOntology = z.infer<typeof OntologyScopeSchema>
export type OrganizationModelSystems = z.infer<typeof SystemsDomainSchema>
export type OrganizationModelSystemEntry = z.infer<typeof SystemEntrySchema>
export type OrganizationModelSystemConfig = z.infer<typeof SystemConfigSchema>
export type OrganizationModelSystemId = z.infer<typeof SystemIdSchema>
export type OrganizationModelSystemPath = z.infer<typeof SystemPathSchema>
export type OrganizationModelSystemKind = z.infer<typeof SystemKindSchema>
export type OrganizationModelSystemLifecycle = z.infer<typeof SystemLifecycleSchema>
export type OrganizationModelSystemInterfaceKey = z.infer<typeof SystemInterfaceKeySchema>
export type OrganizationModelSystemInterfaceLifecycle = z.infer<typeof SystemInterfaceLifecycleSchema>
export type OrganizationModelSystemInterfaceReadinessProfile = z.infer<typeof SystemInterfaceReadinessProfileSchema>
export type OrganizationModelSystemApiInterface = z.infer<typeof SystemApiInterfaceSchema>
export type OrganizationModelSystemInterfaceRef = z.infer<typeof SystemInterfaceRefSchema>
/** @deprecated Use OrganizationModelSystemLifecycle. Accepted for one publish cycle. */
export type OrganizationModelSystemStatus = z.infer<typeof SystemStatusSchema>
export type OrganizationModelResources = z.infer<typeof ResourcesDomainSchema>
export type OrganizationModelResourceEntry = z.infer<typeof ResourceEntrySchema>
export type OrganizationModelResourceId = z.infer<typeof ResourceIdSchema>
export type OrganizationModelCodeReference = z.infer<typeof CodeReferenceSchema>
export type OrganizationModelCodeReferenceRole = z.infer<typeof CodeReferenceRoleSchema>
export type EventId = z.infer<typeof EventIdSchema>
export type EventEmissionDescriptor = z.infer<typeof EventEmissionDescriptorSchema>
export type EventDescriptor = z.infer<typeof EventDescriptorSchema>
export type OrganizationModelResourceKind = z.infer<typeof ResourceKindSchema>
export type OrganizationModelResourceGovernanceStatus = z.infer<typeof ResourceGovernanceStatusSchema>
export type OrganizationModelResourceOntologyBinding = z.infer<typeof ResourceOntologyBindingSchema>
export type OrganizationModelContractRef = z.infer<typeof ContractRefSchema>
export type OrganizationModelResourceOntologyBindingContract = ResourceOntologyBindingContract
export type { ParsedContractRef }
export type OrganizationModelAgentKind = z.infer<typeof AgentKindSchema>
export type OrganizationModelScriptResourceLanguage = z.infer<typeof ScriptResourceLanguageSchema>
export type OrganizationModelScriptResourceSource = z.infer<typeof ScriptResourceSourceSchema>
export type OrganizationModelWorkflowResourceEntry = z.infer<typeof WorkflowResourceEntrySchema>
export type OrganizationModelAgentResourceEntry = z.infer<typeof AgentResourceEntrySchema>
export type OrganizationModelIntegrationResourceEntry = z.infer<typeof IntegrationResourceEntrySchema>
export type OrganizationModelScriptResourceEntry = z.infer<typeof ScriptResourceEntrySchema>
export type OrganizationModelTopology = z.infer<typeof OmTopologyDomainSchema>
export type OrganizationModelTopologyNodeKind = z.infer<typeof OmTopologyNodeKindSchema>
export type OrganizationModelTopologyNodeRef = z.infer<typeof OmTopologyNodeRefSchema>
export type OrganizationModelTopologyRelationshipKind = z.infer<typeof OmTopologyRelationshipKindSchema>
export type OrganizationModelTopologyRelationship = z.infer<typeof OmTopologyRelationshipSchema>
export type OrganizationModelTopologyMetadata = z.infer<typeof OmTopologyMetadataSchema>
export type OrganizationModelTopologySystemInterfaceGrant = z.infer<typeof OmTopologySystemInterfaceGrantSchema>
export type OrganizationModelTopologySystemInterfaceGrantMetadata = z.infer<
  typeof OmTopologySystemInterfaceGrantMetadataSchema
>
export type OrganizationModelActions = z.infer<typeof ActionsDomainSchema>
export type OrganizationModelAction = z.infer<typeof ActionSchema>
export type OrganizationModelActionId = z.infer<typeof ActionIdSchema>
export type OrganizationModelActionScope = z.infer<typeof ActionScopeSchema>
export type OrganizationModelActionRef = z.infer<typeof ActionRefSchema>
export type OrganizationModelActionInvocationKind = z.infer<typeof ActionInvocationKindSchema>
export type OrganizationModelActionInvocation = z.infer<typeof ActionInvocationSchema>
export type EntityId = z.infer<typeof EntityIdSchema>
export type EntityLink = z.infer<typeof EntityLinkSchema>
export type Entity = z.infer<typeof EntitySchema>
export type OrganizationModelEntity = z.infer<typeof EntitySchema>
export type OrganizationModelEntities = z.infer<typeof EntitiesDomainSchema>
export type OrganizationModelPolicies = z.infer<typeof PoliciesDomainSchema>
export type OrganizationModelPolicy = z.infer<typeof PolicySchema>
export type OrganizationModelPolicyId = z.infer<typeof PolicyIdSchema>
export type OrganizationModelPolicyApplicability = z.infer<typeof PolicyApplicabilitySchema>
export type OrganizationModelPolicyTrigger = z.infer<typeof PolicyTriggerSchema>
export type OrganizationModelPolicyPredicate = z.infer<typeof PolicyPredicateSchema>
export type OrganizationModelPolicyEffect = z.infer<typeof PolicyEffectSchema>
export type OrganizationModelKnowledge = z.infer<typeof KnowledgeDomainSchema>
export type OrgKnowledgeNode = z.infer<typeof OrgKnowledgeNodeSchema>
export type OrgKnowledgeNodeInput = z.input<typeof OrgKnowledgeNodeSchema>
export type OrgKnowledgeKind = z.infer<typeof OrgKnowledgeKindSchema>
export type KnowledgeTargetKind = z.infer<typeof KnowledgeTargetKindSchema>
export type KnowledgeTargetRef = z.infer<typeof KnowledgeTargetRefSchema>
export type KnowledgeLink = z.infer<typeof KnowledgeLinkSchema>
export type OrganizationModelIconToken = z.infer<typeof OrganizationModelIconTokenSchema>
export type OrganizationModelBuiltinIconToken = z.infer<typeof OrganizationModelBuiltinIconTokenSchema>

export type DeepPartial<T> =
  T extends Array<infer U> ? Array<DeepPartial<U>> : T extends object ? { [K in keyof T]?: DeepPartial<T[K]> } : T
