{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schema.ontai.dev/v1alpha1/domain-core/DomainWorkflow.json",
  "title": "DomainWorkflow",
  "description": "Lifecycle workflow declaration for a domain identity. Defines the phases, entry conditions, terminal states, and transition authority that govern the operational lifecycle of domain resources. No controller runs at Layer 0.",
  "x-ont-layer": "domain-core",
  "x-ont-stability": "alpha",
  "x-ont-depends-on": [
    {"group": "core.ontai.dev", "kind": "DomainIdentity", "version": "v1alpha1"}
  ],
  "type": "object",
  "required": ["apiVersion", "kind", "metadata", "spec"],
  "properties": {
    "apiVersion": {
      "type": "string",
      "const": "core.ontai.dev/v1alpha1",
      "description": "API version for this resource."
    },
    "kind": {
      "type": "string",
      "const": "DomainWorkflow",
      "description": "Resource kind."
    },
    "metadata": {
      "$ref": "https://schema.ontai.dev/v1alpha1/shared/KubernetesMetadata.json",
      "description": "Standard Kubernetes object metadata."
    },
    "spec": {
      "type": "object",
      "description": "Desired state of the DomainWorkflow.",
      "required": ["domainIdentityRef"],
      "properties": {
        "domainIdentityRef": {
          "type": "object",
          "description": "Structured reference to the DomainIdentity whose lifecycle this workflow governs.",
          "required": ["group", "kind", "version", "name"],
          "properties": {
            "group": { "type": "string", "const": "core.ontai.dev" },
            "kind": { "type": "string", "const": "DomainIdentity" },
            "version": { "type": "string", "const": "v1alpha1" },
            "name": { "type": "string", "description": "Name of the DomainIdentity resource." }
          },
          "additionalProperties": false
        },
        "phases": {
          "type": "array",
          "description": "Ordered list of phase names in this workflow. Each name should correspond to a phase in the referenced domain's PhaseModel.",
          "items": {
            "type": "string"
          }
        },
        "entryConditions": {
          "type": "object",
          "description": "Map of phase name to list of condition type strings that must be satisfied before that phase may begin.",
          "additionalProperties": {
            "type": "array",
            "items": { "type": "string" }
          }
        },
        "terminalStates": {
          "type": "array",
          "description": "List of phase names that represent terminal states in this workflow. A workflow instance reaching a terminal state requires explicit operator action to restart.",
          "items": {
            "type": "string"
          }
        },
        "transitionAuthority": {
          "type": "string",
          "description": "Name of the operator or controller that holds authority to advance workflow state transitions (e.g., platform, conductor)."
        }
      },
      "additionalProperties": false
    },
    "status": {
      "type": "object",
      "description": "Observed state of the DomainWorkflow.",
      "properties": {
        "conditions": {
          "type": "array",
          "description": "Standard Kubernetes condition array for this resource.",
          "items": { "$ref": "#/$defs/Condition" }
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false,
  "$defs": {
    "Condition": {
      "type": "object",
      "required": ["type", "status", "lastTransitionTime", "reason", "message"],
      "properties": {
        "type": { "type": "string" },
        "status": { "type": "string", "enum": ["True", "False", "Unknown"] },
        "lastTransitionTime": { "type": "string", "format": "date-time" },
        "reason": { "type": "string" },
        "message": { "type": "string" },
        "observedGeneration": { "type": "integer" }
      },
      "additionalProperties": false
    }
  }
}
