{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://qrtrust.local/contracts/destination-policy.schema.json",
  "title": "QR Trust destination policy",
  "type": "object",
  "required": [
    "artifact_type",
    "schema_version",
    "root_program_id",
    "delegated_authority_id",
    "issuer_id",
    "destination_policy_id",
    "approved_destinations",
    "redirect_policy",
    "runtime_safety_policy",
    "publication"
  ],
  "properties": {
    "artifact_type": {
      "const": "destination_policy"
    },
    "schema_version": {
      "type": "string",
      "minLength": 1
    },
    "fixture_notice": {
      "type": "string"
    },
    "root_program_id": {
      "type": "string",
      "pattern": "^root:"
    },
    "delegated_authority_id": {
      "type": "string",
      "pattern": "^authority:"
    },
    "issuer_id": {
      "type": "string",
      "pattern": "^issuer:"
    },
    "destination_policy_id": {
      "type": "string",
      "pattern": "^policy:"
    },
    "approved_destinations": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "destination_id",
          "expected_final_url",
          "allowed_hosts",
          "allow_subdomains",
          "path_prefixes",
          "query_policy"
        ],
        "properties": {
          "destination_id": {
            "type": "string",
            "pattern": "^dest:"
          },
          "expected_final_url": {
            "type": "string",
            "format": "uri"
          },
          "allowed_hosts": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string",
              "minLength": 1
            }
          },
          "allow_subdomains": {
            "type": "boolean"
          },
          "path_prefixes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "query_policy": {
            "type": "string",
            "enum": [
              "none",
              "allow_known_payment_query"
            ]
          }
        },
        "additionalProperties": true
      }
    },
    "redirect_policy": {
      "type": "object",
      "required": [
        "resolver_urls",
        "expected_final_destinations",
        "allowed_redirect_hosts",
        "max_redirect_hops",
        "nested_shorteners_allowed",
        "scanner_must_display_resolver_and_final_destination"
      ],
      "properties": {
        "resolver_urls": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uri"
          }
        },
        "expected_final_destinations": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uri"
          }
        },
        "allowed_redirect_hosts": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "max_redirect_hops": {
          "type": "integer",
          "minimum": 0
        },
        "nested_shorteners_allowed": {
          "type": "boolean"
        },
        "scanner_must_display_resolver_and_final_destination": {
          "type": "boolean"
        },
        "fixture_redirect_markers": {
          "type": "object"
        }
      },
      "additionalProperties": true
    },
    "runtime_safety_policy": {
      "type": "object",
      "required": [
        "provider",
        "verdict_ttl_seconds",
        "stale_behavior",
        "unavailable_behavior"
      ],
      "properties": {
        "provider": {
          "type": "string",
          "minLength": 1
        },
        "verdict_ttl_seconds": {
          "type": "integer",
          "minimum": 0
        },
        "stale_behavior": {
          "enum": [
            "allow",
            "downgrade_to_caution",
            "downgrade_or_block",
            "block"
          ]
        },
        "unavailable_behavior": {
          "enum": [
            "allow",
            "downgrade_to_caution",
            "downgrade_or_block",
            "block"
          ]
        },
        "fixture_verdict_markers": {
          "type": "object"
        }
      },
      "additionalProperties": true
    },
    "publication": {
      "$ref": "#/$defs/publication"
    }
  },
  "additionalProperties": false,
  "$defs": {
    "publication": {
      "type": "object",
      "required": [
        "published_at",
        "valid_until",
        "signed_by",
        "signature_status"
      ],
      "properties": {
        "published_at": {
          "type": "string",
          "format": "date-time"
        },
        "valid_until": {
          "type": "string",
          "format": "date-time"
        },
        "signed_by": {
          "type": "string",
          "minLength": 1
        },
        "signature_status": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": true
    }
  }
}
