{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.bounder.io/schemas/creedspace-bounder-policy-v1.schema.json",
  "title": "Creed Space Bounder Device Policy v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "version",
    "policy_id",
    "issuer",
    "subject",
    "fleet_id",
    "sequence",
    "issued_at",
    "not_before",
    "expires_at",
    "source_policies",
    "constraints"
  ],
  "properties": {
    "version": {
      "const": "creedspace-bounder-policy/v1"
    },
    "policy_id": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "issuer": {
      "const": "creed.space/fleet"
    },
    "subject": {
      "type": "string",
      "minLength": 1,
      "maxLength": 255,
      "pattern": "\\S"
    },
    "fleet_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 255,
      "pattern": "\\S"
    },
    "sequence": {
      "type": "integer",
      "minimum": 1,
      "maximum": 9007199254740991
    },
    "issued_at": {
      "$ref": "#/$defs/utcDateTime"
    },
    "not_before": {
      "$ref": "#/$defs/utcDateTime"
    },
    "expires_at": {
      "$ref": "#/$defs/utcDateTime"
    },
    "source_policies": {
      "type": "array",
      "minItems": 1,
      "maxItems": 64,
      "uniqueItems": true,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "version",
          "level"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255,
            "pattern": "\\S"
          },
          "version": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64,
            "pattern": "\\S"
          },
          "level": {
            "enum": [
              "constitutional",
              "org",
              "team",
              "agent"
            ]
          }
        }
      }
    },
    "constraints": {
      "$ref": "creedspace-bounder-profile-v1.schema.json#/$defs/constraints"
    }
  },
  "$defs": {
    "utcDateTime": {
      "type": "string",
      "maxLength": 64,
      "format": "date-time",
      "pattern": "^(?!0000-)\\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\\d|3[01])T(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d{1,9})?Z$"
    }
  }
}
