{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://paulkov.github.io/dpone/schemas/gitops/deployment-cache-recovery-plan.schema.json",
  "title": "dpone GitOps deployment cache recovery plan",
  "type": "object",
  "required": [
    "schema",
    "environment",
    "status",
    "current_deployment_id",
    "current_path_deployment_id",
    "preferred_repair_deployment_id",
    "issues",
    "repair_candidates"
  ],
  "additionalProperties": true,
  "properties": {
    "schema": {
      "const": "dpone.deployment-cache-recovery-plan.v1"
    },
    "environment": {
      "type": "string",
      "minLength": 1
    },
    "status": {
      "enum": [
        "ok",
        "repairable",
        "blocked"
      ]
    },
    "current_deployment_id": {
      "anyOf": [
        {
          "$ref": "#/$defs/sha256"
        },
        {
          "type": "null"
        }
      ]
    },
    "current_path_deployment_id": {
      "anyOf": [
        {
          "$ref": "#/$defs/sha256"
        },
        {
          "type": "null"
        }
      ]
    },
    "preferred_repair_deployment_id": {
      "anyOf": [
        {
          "$ref": "#/$defs/sha256"
        },
        {
          "type": "null"
        }
      ]
    },
    "issues": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/issue"
      }
    },
    "repair_candidates": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/candidate"
      }
    }
  },
  "$defs": {
    "sha256": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "issue": {
      "type": "object",
      "required": [
        "code",
        "severity",
        "message",
        "path"
      ],
      "additionalProperties": true,
      "properties": {
        "code": {
          "type": "string",
          "pattern": "^DPONE_(CACHE|CURRENT|DEPLOYMENT|AIRFLOW|RELEASE)_[A-Z0-9_]+$"
        },
        "severity": {
          "enum": [
            "error",
            "warning"
          ]
        },
        "message": {
          "type": "string",
          "minLength": 1
        },
        "path": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "candidate": {
      "type": "object",
      "required": [
        "deployment_id",
        "path",
        "reason"
      ],
      "additionalProperties": true,
      "properties": {
        "deployment_id": {
          "$ref": "#/$defs/sha256"
        },
        "path": {
          "type": "string",
          "minLength": 1
        },
        "reason": {
          "enum": [
            "current_state",
            "complete"
          ]
        }
      }
    }
  }
}
