{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:orbiplex:schema:artifact-location-advice:v1",
  "title": "Artifact Location Advice v1",
  "description": "Bounded, non-authoritative location hints for exact or related artifact targets. Advice never creates a source, grants credentials, changes the primary INAC payload location, or authorizes recursive resolution.",
  "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", "advice/items"],
  "properties": {
    "schema": { "const": "artifact-location-advice.v1" },
    "schema/v": { "const": 1 },
    "advice/items": {
      "type": "array",
      "minItems": 1,
      "maxItems": 16,
      "items": { "$ref": "#/$defs/item" }
    }
  },
  "$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]+$" },
    "target": {
      "type": "object",
      "additionalProperties": false,
      "required": ["artifact/id", "artifact/digest", "artifact/size-bytes"],
      "properties": {
        "artifact/id": { "type": "string", "minLength": 1, "maxLength": 512, "pattern": "^[^\\s\\u0000]+$" },
        "artifact/digest": { "$ref": "#/$defs/digest" },
        "artifact/size-bytes": { "type": "integer", "minimum": 0, "maximum": 67108864 }
      }
    },
    "selector": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "value"],
      "properties": {
        "kind": { "enum": ["whole-resource", "whole-text", "line-range", "html-element-id", "mime-part"] },
        "value": { "type": "string", "minLength": 1, "maxLength": 512, "pattern": "^[^\\u0000-\\u001F\\u007F]+$" }
      }
    },
    "location": {
      "type": "object",
      "additionalProperties": false,
      "required": ["href", "carrier/mode", "expires/at"],
      "properties": {
        "href": {
          "type": "string",
          "minLength": 9,
          "maxLength": 4096,
          "oneOf": [
            { "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]*)?$" },
            { "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}$" }
          ]
        },
        "carrier/mode": { "enum": ["exact-resource", "embedded-artifact"] },
        "extraction/profile-ref": { "$ref": "#/$defs/ref" },
        "extraction/profile-digest": { "$ref": "#/$defs/digest" },
        "selector": { "$ref": "#/$defs/selector" },
        "expires/at": { "type": "string", "format": "date-time" }
      },
      "allOf": [
        {
          "if": { "properties": { "carrier/mode": { "const": "embedded-artifact" } } },
          "then": { "required": ["extraction/profile-ref", "extraction/profile-digest", "selector"] },
          "else": {
            "not": {
              "anyOf": [
                { "required": ["extraction/profile-ref"] },
                { "required": ["extraction/profile-digest"] },
                { "required": ["selector"] }
              ]
            }
          }
        }
      ]
    },
    "item": {
      "type": "object",
      "additionalProperties": false,
      "required": ["relation", "target", "locations"],
      "properties": {
        "relation": { "enum": ["alternate-exact", "fallback-exact", "related-artifact"] },
        "target": { "$ref": "#/$defs/target" },
        "locations": {
          "type": "array",
          "minItems": 1,
          "maxItems": 8,
          "items": { "$ref": "#/$defs/location" }
        }
      }
    }
  }
}
