{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "overdeck.delivery/v1/project",
  "title": "Overdeck delivery project contract v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "contract_version",
    "project",
    "repository",
    "ci_adapter",
    "build_outputs",
    "deployment_units",
    "activation_order",
    "migration",
    "credential_references",
    "ownership_manifest"
  ],
  "properties": {
    "contract_version": { "const": "overdeck.delivery/v1" },
    "project": { "$ref": "#/$defs/id" },
    "repository": { "type": "string", "format": "uri", "minLength": 1 },
    "ci_adapter": { "type": "string", "minLength": 1 },
    "build_outputs": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/buildOutput" }
    },
    "deployment_units": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/deploymentUnit" }
    },
    "activation_order": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/id" },
      "uniqueItems": true
    },
    "migration": {
      "type": "object",
      "additionalProperties": false,
      "required": ["supported", "compatibility_policy"],
      "properties": {
        "supported": { "type": "boolean" },
        "compatibility_policy": { "type": "string", "minLength": 1 }
      }
    },
    "credential_references": {
      "type": "array",
      "items": { "$ref": "#/$defs/credentialReference" }
    },
    "ownership_manifest": { "type": "string", "minLength": 1 }
  },
  "$defs": {
    "id": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._/-]*$" },
    "digest": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9+._-]*:[A-Fa-f0-9]{32,}$"
    },
    "buildOutput": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "kind", "path", "media_type"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "kind": { "enum": ["oci_image", "bundle", "archive", "file"] },
        "path": { "type": "string", "minLength": 1 },
        "media_type": { "type": "string", "minLength": 1 }
      }
    },
    "deploymentUnit": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "target", "rollback"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "target": { "type": "string", "minLength": 1 },
        "rollback": {
          "type": "object",
          "additionalProperties": false,
          "required": ["supported", "capability"],
          "properties": {
            "supported": { "type": "boolean" },
            "capability": { "type": "string", "minLength": 1 }
          }
        }
      }
    },
    "credentialReference": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "purpose"],
      "properties": {
        "id": { "$ref": "#/$defs/id" },
        "purpose": { "type": "string", "minLength": 1 }
      }
    }
  }
}
