{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:orbiplex:schema:artifact-source:v1",
  "title": "Artifact Source v1",
  "description": "Immutable operator-owned declaration for one read-only artifact source generation. Locators contain references or public URLs, never credential values or executable paths.",
  "type": "object",
  "additionalProperties": false,
  "x-dia-workflow": "project",
  "x-dia-status": "draft",
  "x-dia-basis": [
    "doc/project/40-proposals/088-pull-based-artifact-acquisition.md"
  ],
  "required": [
    "schema",
    "schema/v",
    "source/id",
    "source/generation",
    "connector/id",
    "locator",
    "trigger/modes",
    "allow",
    "extraction",
    "admission/mode",
    "limits",
    "freshness/max-staleness-seconds",
    "consumption/mode",
    "operator/binding-ref"
  ],
  "properties": {
    "schema": { "const": "artifact-source.v1" },
    "schema/v": { "const": 1 },
    "source/id": { "type": "string", "minLength": 17, "maxLength": 256, "pattern": "^artifact-source:[A-Za-z0-9][A-Za-z0-9._:-]*$" },
    "source/generation": { "type": "integer", "minimum": 1, "maximum": 9007199254740991 },
    "connector/id": { "type": "string", "minLength": 27, "maxLength": 256, "pattern": "^artifact-source-connector:[A-Za-z0-9][A-Za-z0-9._:-]*$" },
    "locator": { "$ref": "#/$defs/locator" },
    "credential/ref": { "$ref": "#/$defs/ref" },
    "trigger/modes": {
      "type": "array",
      "minItems": 1,
      "maxItems": 3,
      "uniqueItems": true,
      "items": { "enum": ["manual", "scheduled", "event"] }
    },
    "allow": { "$ref": "#/$defs/allow" },
    "extraction": { "$ref": "#/$defs/extraction" },
    "admission/mode": { "enum": ["stage", "admit-known"] },
    "admission/table-ref": { "$ref": "#/$defs/ref" },
    "limits": { "$ref": "#/$defs/limits" },
    "freshness/max-staleness-seconds": { "type": "integer", "minimum": 1, "maximum": 31536000 },
    "consumption/mode": { "const": "read-only" },
    "checkpoint/policy": { "enum": ["none", "generation-bound"] },
    "operator/binding-ref": { "$ref": "#/$defs/ref" }
  },
  "allOf": [
    {
      "if": { "properties": { "admission/mode": { "const": "admit-known" } } },
      "then": { "required": ["admission/table-ref"] },
      "else": { "not": { "required": ["admission/table-ref"] } }
    }
  ],
  "$defs": {
    "digest": { "type": "string", "pattern": "^sha256:[A-Za-z0-9_-]{43}$" },
    "ref": { "type": "string", "minLength": 3, "maxLength": 512, "pattern": "^[a-z][a-z0-9.-]*:[^\\s\\u0000-\\u001F\\u007F]+$" },
    "locator": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "fixture/ref"],
          "properties": {
            "kind": { "const": "fixed-fixture" },
            "fixture/ref": { "$ref": "#/$defs/ref" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "path/ref"],
          "properties": {
            "kind": { "const": "operator-path-ref" },
            "path/ref": { "$ref": "#/$defs/ref" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "paste/ref"],
          "properties": {
            "kind": { "const": "operator-paste-ref" },
            "paste/ref": { "$ref": "#/$defs/ref" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "url"],
          "properties": {
            "kind": { "const": "https-url" },
            "url": { "type": "string", "minLength": 9, "maxLength": 4096, "pattern": "^https://(?![^/?#\\s]*@)(?![^#\\s]*[?&]=)(?![^#\\s]*[?&](?:[Tt][Oo][Kk][Ee][Nn]|[Aa][Cc][Cc][Ee][Ss][Ss]_[Tt][Oo][Kk][Ee][Nn]|[Oo][Aa][Uu][Tt][Hh]_[Tt][Oo][Kk][Ee][Nn]|[Kk][Ee][Yy]|[Aa][Pp][Ii]_[Kk][Ee][Yy]|[Aa][Pp][Ii][Kk][Ee][Yy]|[Ss][Ee][Cc][Rr][Ee][Tt]|[Cc][Ll][Ii][Ee][Nn][Tt]_[Ss][Ee][Cc][Rr][Ee][Tt]|[Ss][Ii][Gg][Nn][Aa][Tt][Uu][Rr][Ee]|[Ss][Ii][Gg]|[Cc][Rr][Ee][Dd][Ee][Nn][Tt][Ii][Aa][Ll]|[Pp][Aa][Ss][Ss][Ww][Oo][Rr][Dd]|[Aa][Uu][Tt][Hh]|[Aa][Uu][Tt][Hh][Oo][Rr][Ii][Zz][Aa][Tt][Ii][Oo][Nn]|[Bb][Ee][Aa][Rr][Ee][Rr]|[Ss][Ee][Ss][Ss][Ii][Oo][Nn]_[Ii][Dd])=)(?![^#\\s]*[?&][^=&#%]*%[^=&#]*=)[^/?#\\s]+(?:/[^?#\\s]*)?(?:\\?[^#\\s]*)?$" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "artifact/ref"],
          "properties": {
            "kind": { "const": "inac-logical-ref" },
            "artifact/ref": { "type": "string", "minLength": 1, "maxLength": 2048, "pattern": "^inac:artifact:(?:[A-Za-z0-9._~-]|%[0-9A-F]{2})+:(?:[A-Za-z0-9._~-]|%[0-9A-F]{2})+:sha256:[A-Za-z0-9_-]{43}$" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "mailbox/ref"],
          "properties": {
            "kind": { "const": "mailbox-ref" },
            "mailbox/ref": { "$ref": "#/$defs/ref" }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "volume/ref"],
          "properties": {
            "kind": { "const": "removable-media-ref" },
            "volume/ref": { "$ref": "#/$defs/ref" }
          }
        }
      ]
    },
    "allow": {
      "type": "object",
      "additionalProperties": false,
      "required": ["inner/schemas", "artifact/families", "trust/domains"],
      "properties": {
        "inner/schemas": { "$ref": "#/$defs/nonEmptyStringSet" },
        "artifact/families": { "$ref": "#/$defs/nonEmptyStringSet" },
        "trust/domains": { "$ref": "#/$defs/nonEmptyStringSet" }
      }
    },
    "nonEmptyStringSet": {
      "type": "array",
      "minItems": 1,
      "maxItems": 64,
      "uniqueItems": true,
      "items": { "type": "string", "minLength": 1, "maxLength": 256, "pattern": "^[^\\s\\u0000]+$" }
    },
    "extraction": {
      "type": "object",
      "additionalProperties": false,
      "required": ["carrier/mode", "profile/ref", "profile/digest"],
      "properties": {
        "carrier/mode": { "enum": ["exact-resource", "embedded-artifact"] },
        "profile/ref": { "$ref": "#/$defs/ref" },
        "profile/digest": { "$ref": "#/$defs/digest" }
      }
    },
    "limits": {
      "type": "object",
      "additionalProperties": false,
      "required": ["carrier/bytes-max", "candidates/max", "candidate/bytes-max", "duration/ms-max"],
      "properties": {
        "carrier/bytes-max": { "type": "integer", "minimum": 1, "maximum": 67108864 },
        "candidates/max": { "type": "integer", "minimum": 1, "maximum": 64 },
        "candidate/bytes-max": { "type": "integer", "minimum": 1, "maximum": 8388608 },
        "duration/ms-max": { "type": "integer", "minimum": 1, "maximum": 120000 }
      }
    }
  }
}
