{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://uqp.dev/spec/v0.1/schemas/discovery.json",
  "title": "UQP peer discovery",
  "description": "Neutral reference discovery for UQP definitions and optional provider routing hints.",
  "type": "object",
  "properties": {
    "protocol": {
      "const": "uqp"
    },
    "spec_version": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
    },
    "endpoints": {
      "type": "object",
      "properties": {
        "rest": {
          "type": "string",
          "format": "uri"
        },
        "mcp": {
          "type": "string",
          "format": "uri"
        },
        "graphql": {
          "type": "string",
          "format": "uri"
        }
      },
      "minProperties": 1,
      "additionalProperties": false
    },
    "supported_packs": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "pack_id": {
            "type": "string",
            "minLength": 1
          },
          "pack_version": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "pack_id",
          "pack_version"
        ],
        "additionalProperties": false
      }
    },
    "routing_policy": {
      "$ref": "common.json#/$defs/routingPolicy"
    },
    "checkout_handoffs": {
      "type": "array",
      "items": {
        "enum": [
          "ucp",
          "acp"
        ]
      },
      "uniqueItems": true
    },
    "documentation_url": {
      "type": "string",
      "format": "uri"
    },
    "review_sla_seconds": {
      "type": "integer",
      "minimum": 1
    },
    "notes": {
      "type": "string"
    },
    "keys": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/publicJwk"
      }
    }
  },
  "required": [
    "protocol",
    "spec_version",
    "endpoints",
    "supported_packs",
    "routing_policy",
    "checkout_handoffs",
    "documentation_url"
  ],
  "additionalProperties": false,
  "$defs": {
    "publicJwk": {
      "type": "object",
      "properties": {
        "kty": {
          "enum": [
            "OKP",
            "EC"
          ]
        },
        "kid": {
          "type": "string",
          "minLength": 1
        },
        "use": {
          "const": "sig"
        },
        "alg": {
          "enum": [
            "EdDSA",
            "ES256"
          ]
        },
        "crv": {
          "enum": [
            "Ed25519",
            "P-256"
          ]
        },
        "x": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{43}$"
        },
        "y": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{43}$"
        }
      },
      "required": [
        "kty",
        "kid",
        "alg",
        "crv",
        "x"
      ],
      "additionalProperties": false,
      "oneOf": [
        {
          "properties": {
            "kty": {
              "const": "OKP"
            },
            "alg": {
              "const": "EdDSA"
            },
            "crv": {
              "const": "Ed25519"
            }
          },
          "not": {
            "required": [
              "y"
            ],
            "properties": {
              "y": {}
            }
          }
        },
        {
          "properties": {
            "kty": {
              "const": "EC"
            },
            "alg": {
              "const": "ES256"
            },
            "crv": {
              "const": "P-256"
            },
            "y": {}
          },
          "required": [
            "y"
          ]
        }
      ]
    }
  }
}
