{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:asif:continuation-report:0.2",
  "title": "ASIF destination continuation report",
  "type": "object",
  "properties": {
    "report_version": {
      "const": "0.2"
    },
    "evaluation_mode": {
      "enum": [
        "synthetic",
        "observed"
      ]
    },
    "id": {
      "type": "string",
      "minLength": 1
    },
    "source": {
      "type": "object",
      "properties": {
        "session_id": {
          "type": "string",
          "minLength": 1
        },
        "capture_id": {
          "type": "string",
          "minLength": 1
        },
        "plan_id": {
          "type": "string",
          "minLength": 1
        },
        "document_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}(?![\\s\\S])"
        }
      },
      "required": [
        "session_id",
        "capture_id",
        "plan_id",
        "document_sha256"
      ],
      "additionalProperties": true
    },
    "destination": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "runtime": {
          "$ref": "#/$defs/runtime"
        },
        "capabilities_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}(?![\\s\\S])"
        },
        "capabilities_snapshot": {
          "$ref": "#/$defs/snapshot_evidence"
        }
      },
      "required": [
        "id",
        "runtime",
        "capabilities_sha256",
        "capabilities_snapshot"
      ],
      "additionalProperties": true
    },
    "assessed_at": {
      "type": "string",
      "minLength": 1
    },
    "expires_at": {
      "type": "string",
      "minLength": 1
    },
    "outcome": {
      "enum": [
        "ready",
        "blocked",
        "adaptation_required"
      ]
    },
    "assessments": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/assessment"
      },
      "minItems": 1
    },
    "path_bindings": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "root_id": {
            "type": "string",
            "minLength": 1
          },
          "destination_path": {
            "type": "string",
            "minLength": 1
          },
          "case_sensitive": {
            "type": "boolean"
          },
          "unicode_normalization": {
            "enum": [
              "none",
              "NFC",
              "NFD"
            ]
          }
        },
        "required": [
          "root_id",
          "destination_path",
          "case_sensitive",
          "unicode_normalization"
        ],
        "additionalProperties": true
      },
      "minItems": 0
    },
    "identity_mappings": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "entity_type": {
            "type": "string",
            "minLength": 1
          },
          "source_id": {
            "type": "string",
            "minLength": 1
          },
          "target_id": {
            "type": "string",
            "minLength": 1
          },
          "target_namespace": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "entity_type",
          "source_id",
          "target_id",
          "target_namespace"
        ],
        "additionalProperties": true
      },
      "minItems": 0
    },
    "transformations": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/transformation"
      },
      "minItems": 0
    },
    "model_assessment": {
      "type": "object",
      "properties": {
        "source": {
          "$ref": "#/$defs/model"
        },
        "target": {
          "$ref": "#/$defs/model"
        },
        "tokenizer": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1
            },
            {
              "type": "null"
            }
          ]
        },
        "input_tokens": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            {
              "type": "null"
            }
          ]
        },
        "input_limit": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            {
              "type": "null"
            }
          ]
        },
        "output_reserve": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "fit": {
          "enum": [
            "fits",
            "exceeds",
            "unknown"
          ]
        }
      },
      "required": [
        "source",
        "target",
        "tokenizer",
        "input_tokens",
        "input_limit",
        "output_reserve",
        "fit"
      ],
      "additionalProperties": true
    },
    "blocking_reasons": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "subject": {
            "$ref": "#/$defs/subject"
          },
          "reason": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "subject",
          "reason"
        ],
        "additionalProperties": true
      },
      "minItems": 0
    },
    "evidence": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/evidence"
      },
      "minItems": 0
    },
    "import_result": {
      "type": "object",
      "properties": {
        "status": {
          "enum": [
            "not_attempted",
            "imported",
            "failed",
            "rolled_back"
          ]
        },
        "evidence_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0,
          "uniqueItems": true
        },
        "detail": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "status",
        "evidence_ids",
        "detail"
      ],
      "additionalProperties": true
    },
    "continuation_result": {
      "type": "object",
      "properties": {
        "status": {
          "enum": [
            "not_tested",
            "continued",
            "blocked",
            "failed"
          ]
        },
        "evidence_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0,
          "uniqueItems": true
        },
        "detail": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "status",
        "evidence_ids",
        "detail"
      ],
      "additionalProperties": true
    }
  },
  "required": [
    "report_version",
    "evaluation_mode",
    "id",
    "source",
    "destination",
    "assessed_at",
    "expires_at",
    "outcome",
    "assessments",
    "path_bindings",
    "identity_mappings",
    "transformations",
    "model_assessment",
    "blocking_reasons",
    "evidence",
    "import_result",
    "continuation_result"
  ],
  "additionalProperties": true,
  "$defs": {
    "runtime": {
      "type": "object",
      "properties": {
        "agent": {
          "$ref": "#/$defs/agent"
        },
        "adapter": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "version": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "id",
            "version"
          ],
          "additionalProperties": true
        },
        "os": {
          "type": "string",
          "minLength": 1
        },
        "architecture": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "agent",
        "adapter",
        "os",
        "architecture"
      ],
      "additionalProperties": true
    },
    "agent": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "version": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1
            },
            {
              "type": "null"
            }
          ]
        },
        "state_format": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "id",
        "version",
        "state_format"
      ],
      "additionalProperties": true
    },
    "model": {
      "type": "object",
      "properties": {
        "provider": {
          "type": "string",
          "minLength": 1
        },
        "id": {
          "type": "string",
          "minLength": 1
        },
        "revision": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "provider",
        "id",
        "revision"
      ],
      "additionalProperties": true
    },
    "subject": {
      "type": "object",
      "properties": {
        "kind": {
          "enum": [
            "plan",
            "context",
            "model",
            "workspace",
            "dependency",
            "service",
            "configuration",
            "instruction",
            "capability",
            "policy",
            "resource",
            "operation",
            "native_import",
            "feature",
            "environment",
            "checkpoint_requirement",
            "environment_requirement"
          ]
        },
        "id": {
          "type": "string",
          "minLength": 1
        },
        "owner_id": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "kind",
        "id"
      ],
      "additionalProperties": true
    },
    "assessment": {
      "type": "object",
      "properties": {
        "subject": {
          "$ref": "#/$defs/subject"
        },
        "status": {
          "enum": [
            "supported",
            "adapted",
            "omitted",
            "unresolved",
            "unsupported"
          ]
        },
        "required": {
          "type": "boolean"
        },
        "detail": {
          "type": "string",
          "minLength": 1
        },
        "evidence_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0,
          "uniqueItems": true
        },
        "resolved": {
          "type": "object",
          "properties": {
            "identity": {
              "type": "string",
              "minLength": 1
            },
            "version": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1
                },
                {
                  "type": "null"
                }
              ]
            },
            "account": {
              "type": "object",
              "properties": {
                "provider": {
                  "type": "string",
                  "minLength": 1
                },
                "subject": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "required": [
                "provider",
                "subject"
              ],
              "additionalProperties": true
            },
            "scopes": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              },
              "minItems": 0,
              "uniqueItems": true
            },
            "audience": {
              "type": "string",
              "minLength": 1
            },
            "endpoint": {
              "type": "string",
              "minLength": 1
            },
            "secret_handles": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              },
              "minItems": 0,
              "uniqueItems": true
            },
            "status": {
              "enum": [
                "available"
              ]
            },
            "recovery_strategy": {
              "enum": [
                "reconcile",
                "reconnect"
              ]
            },
            "external_identity": {
              "type": "object",
              "properties": {
                "namespace": {
                  "type": "string",
                  "minLength": 1
                },
                "value": {
                  "type": "string",
                  "minLength": 1
                }
              },
              "required": [
                "namespace",
                "value"
              ],
              "additionalProperties": true
            }
          },
          "required": [],
          "additionalProperties": true
        },
        "component_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0,
          "uniqueItems": true
        }
      },
      "required": [
        "subject",
        "status",
        "required",
        "detail",
        "evidence_ids",
        "component_ids"
      ],
      "additionalProperties": true
    },
    "capability_component": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "kind": {
          "enum": [
            "dependency",
            "configuration",
            "policy",
            "capability",
            "model",
            "service",
            "workspace",
            "operation",
            "native_import",
            "environment"
          ]
        },
        "identity": {
          "type": "string",
          "minLength": 1
        },
        "version": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1
            },
            {
              "type": "null"
            }
          ]
        },
        "revision": {
          "type": "string",
          "minLength": 1
        },
        "status": {
          "enum": [
            "available",
            "unavailable",
            "unknown"
          ]
        },
        "model": {
          "$ref": "#/$defs/model"
        },
        "tokenizer": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1
            },
            {
              "type": "null"
            }
          ]
        },
        "input_limit": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            {
              "type": "null"
            }
          ]
        },
        "media_types": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0,
          "uniqueItems": true
        },
        "capabilities": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0,
          "uniqueItems": true
        },
        "account": {
          "$ref": "#/$defs/assessment/properties/resolved/properties/account"
        },
        "audience": {
          "type": "string",
          "minLength": 1
        },
        "scopes": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0,
          "uniqueItems": true
        },
        "secret_handles": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0,
          "uniqueItems": true
        },
        "endpoint": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1
            },
            {
              "type": "null"
            }
          ]
        },
        "root_id": {
          "type": "string",
          "minLength": 1
        },
        "destination_path": {
          "type": "string",
          "minLength": 1
        },
        "case_sensitive": {
          "type": "boolean"
        },
        "unicode_normalization": {
          "enum": [
            "none",
            "NFC",
            "NFD"
          ]
        },
        "recovery_strategy": {
          "enum": [
            "reconcile",
            "reconnect",
            "restart",
            "refuse"
          ]
        },
        "external_identity": {
          "anyOf": [
            {
              "$ref": "#/$defs/assessment/properties/resolved/properties/external_identity"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "id",
        "kind",
        "identity",
        "version",
        "revision",
        "status"
      ],
      "additionalProperties": true,
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "const": "model"
              }
            },
            "required": [
              "kind"
            ]
          },
          "then": {
            "required": [
              "model",
              "tokenizer",
              "input_limit",
              "media_types",
              "capabilities"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "service"
              }
            },
            "required": [
              "kind"
            ]
          },
          "then": {
            "required": [
              "account",
              "audience",
              "scopes",
              "secret_handles",
              "endpoint"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "workspace"
              }
            },
            "required": [
              "kind"
            ]
          },
          "then": {
            "required": [
              "root_id",
              "destination_path",
              "case_sensitive",
              "unicode_normalization"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "kind": {
                "const": "operation"
              }
            },
            "required": [
              "kind"
            ]
          },
          "then": {
            "required": [
              "recovery_strategy",
              "external_identity"
            ]
          }
        }
      ]
    },
    "capability_snapshot": {
      "type": "object",
      "properties": {
        "snapshot_version": {
          "const": "0.1"
        },
        "id": {
          "type": "string",
          "minLength": 1
        },
        "destination_id": {
          "type": "string",
          "minLength": 1
        },
        "producer": {
          "type": "string",
          "minLength": 1
        },
        "evaluation_mode": {
          "enum": [
            "synthetic",
            "observed"
          ]
        },
        "observed_at": {
          "type": "string",
          "minLength": 1
        },
        "expires_at": {
          "type": "string",
          "minLength": 1
        },
        "runtime": {
          "$ref": "#/$defs/runtime"
        },
        "runtime_revision": {
          "type": "string",
          "minLength": 1
        },
        "supported_features": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0,
          "uniqueItems": true
        },
        "components": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/capability_component"
          },
          "minItems": 0
        }
      },
      "required": [
        "snapshot_version",
        "id",
        "destination_id",
        "producer",
        "evaluation_mode",
        "observed_at",
        "expires_at",
        "runtime",
        "runtime_revision",
        "supported_features",
        "components"
      ],
      "additionalProperties": true
    },
    "snapshot_evidence": {
      "type": "object",
      "properties": {
        "format": {
          "type": "string",
          "minLength": 1
        },
        "availability": {
          "enum": [
            "supplied",
            "unavailable"
          ]
        },
        "data": {
          "type": "string",
          "minLength": 1
        },
        "bytes": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "evidence_id": {
          "type": "string",
          "minLength": 1
        },
        "explanation": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "format",
        "availability",
        "evidence_id"
      ],
      "additionalProperties": true,
      "allOf": [
        {
          "if": {
            "properties": {
              "availability": {
                "const": "supplied"
              }
            },
            "required": [
              "availability"
            ]
          },
          "then": {
            "required": [
              "data",
              "bytes"
            ],
            "properties": {
              "bytes": {
                "minimum": 1,
                "maximum": 1048576
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "availability": {
                "const": "unavailable"
              }
            },
            "required": [
              "availability"
            ]
          },
          "then": {
            "required": [
              "explanation"
            ],
            "not": {
              "anyOf": [
                {
                  "required": [
                    "data"
                  ]
                },
                {
                  "required": [
                    "bytes"
                  ]
                }
              ]
            }
          }
        }
      ]
    },
    "evidence": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "producer": {
          "type": "string",
          "minLength": 1
        },
        "time": {
          "type": "string",
          "minLength": 1
        },
        "kind": {
          "enum": [
            "inspection",
            "compatibility_test",
            "authorization",
            "acceptance",
            "import",
            "continuation",
            "synthetic"
          ]
        },
        "detail": {
          "type": "string",
          "minLength": 1
        },
        "reference": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "id",
        "producer",
        "time",
        "kind",
        "detail"
      ],
      "additionalProperties": true
    },
    "transformation": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "subject": {
          "$ref": "#/$defs/subject"
        },
        "target": {
          "type": "string",
          "minLength": 1
        },
        "rule": {
          "type": "string",
          "minLength": 1
        },
        "losses": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0
        },
        "accepted": {
          "type": "boolean"
        },
        "evidence_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0,
          "uniqueItems": true
        }
      },
      "required": [
        "id",
        "subject",
        "target",
        "rule",
        "losses",
        "accepted",
        "evidence_ids"
      ],
      "additionalProperties": true,
      "allOf": [
        {
          "if": {
            "properties": {
              "accepted": {
                "const": true
              }
            },
            "required": [
              "accepted"
            ]
          },
          "then": {
            "properties": {
              "evidence_ids": {
                "minItems": 1
              }
            }
          }
        }
      ]
    },
    "result": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "minLength": 1
        },
        "evidence_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0,
          "uniqueItems": true
        },
        "detail": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "status",
        "evidence_ids",
        "detail"
      ],
      "additionalProperties": true
    }
  }
}
