{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://ansvar.eu/service-portability/switch-export-v1.schema.json",
  "title": "Ansvar switching export v1",
  "description": "Field-level schema for export.json in an Ansvar switching or parallel-use bundle.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "generated_at",
    "organisation",
    "users",
    "seats",
    "entitlements",
    "subscriptions",
    "billing_records",
    "usage_records",
    "documents",
    "workflows",
    "reports",
    "audit_records",
    "tenant_configuration",
    "manifest"
  ],
  "properties": {
    "schema_version": {
      "const": "switch-export-v1"
    },
    "generated_at": {
      "type": "string",
      "format": "date-time"
    },
    "organisation": {
      "$ref": "#/$defs/organisation"
    },
    "users": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/user"
      }
    },
    "seats": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/seat"
      }
    },
    "entitlements": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/entitlement"
      }
    },
    "subscriptions": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/subscription"
      }
    },
    "billing_records": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/billing_record"
      }
    },
    "usage_records": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/usage_record"
      }
    },
    "documents": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/document"
      }
    },
    "workflows": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/workflow"
      }
    },
    "reports": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/report"
      }
    },
    "audit_records": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/audit_record"
      }
    },
    "tenant_configuration": {
      "$ref": "#/$defs/tenant_configuration"
    },
    "manifest": {
      "$ref": "#/$defs/manifest"
    }
  },
  "$defs": {
    "nullable_string": {
      "type": [
        "string",
        "null"
      ]
    },
    "timestamp": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "organisation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "organisation_id",
        "name",
        "created_at"
      ],
      "properties": {
        "organisation_id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "created_at": {
          "$ref": "#/$defs/timestamp"
        }
      }
    },
    "user": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "user_id",
        "email",
        "display_name",
        "status",
        "roles",
        "created_at"
      ],
      "properties": {
        "user_id": {
          "type": "string"
        },
        "email": {
          "$ref": "#/$defs/nullable_string"
        },
        "display_name": {
          "$ref": "#/$defs/nullable_string"
        },
        "status": {
          "type": "string"
        },
        "roles": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "created_at": {
          "$ref": "#/$defs/timestamp"
        }
      }
    },
    "seat": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "seat_id",
        "user_id",
        "product",
        "status",
        "created_at"
      ],
      "properties": {
        "seat_id": {
          "type": "string"
        },
        "user_id": {
          "$ref": "#/$defs/nullable_string"
        },
        "product": {
          "type": "string"
        },
        "status": {
          "type": "string"
        },
        "created_at": {
          "$ref": "#/$defs/timestamp"
        }
      }
    },
    "entitlement": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "entitlement_id",
        "code",
        "tier",
        "quantity",
        "status",
        "starts_at",
        "ends_at"
      ],
      "properties": {
        "entitlement_id": {
          "type": "string"
        },
        "code": {
          "type": "string"
        },
        "tier": {
          "type": "string"
        },
        "quantity": {
          "type": [
            "integer",
            "null"
          ]
        },
        "status": {
          "type": "string"
        },
        "starts_at": {
          "$ref": "#/$defs/timestamp"
        },
        "ends_at": {
          "$ref": "#/$defs/timestamp"
        }
      }
    },
    "subscription": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "subscription_id",
        "product",
        "tier",
        "status",
        "starts_at",
        "ends_at",
        "committed_until"
      ],
      "properties": {
        "subscription_id": {
          "type": "string"
        },
        "product": {
          "type": "string"
        },
        "tier": {
          "type": "string"
        },
        "status": {
          "type": "string"
        },
        "starts_at": {
          "$ref": "#/$defs/timestamp"
        },
        "ends_at": {
          "$ref": "#/$defs/timestamp"
        },
        "committed_until": {
          "$ref": "#/$defs/timestamp"
        }
      }
    },
    "billing_record": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "record_id",
        "kind",
        "status",
        "currency",
        "amount_minor",
        "issued_at",
        "period_start",
        "period_end",
        "invoice_path"
      ],
      "properties": {
        "record_id": {
          "type": "string"
        },
        "kind": {
          "type": "string"
        },
        "status": {
          "type": "string"
        },
        "currency": {
          "$ref": "#/$defs/nullable_string"
        },
        "amount_minor": {
          "type": [
            "integer",
            "null"
          ]
        },
        "issued_at": {
          "$ref": "#/$defs/timestamp"
        },
        "period_start": {
          "$ref": "#/$defs/timestamp"
        },
        "period_end": {
          "$ref": "#/$defs/timestamp"
        },
        "invoice_path": {
          "$ref": "#/$defs/nullable_string"
        }
      }
    },
    "usage_record": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "metric",
        "period_start",
        "period_end",
        "quantity",
        "unit"
      ],
      "properties": {
        "metric": {
          "type": "string"
        },
        "period_start": {
          "$ref": "#/$defs/timestamp"
        },
        "period_end": {
          "$ref": "#/$defs/timestamp"
        },
        "quantity": {
          "type": "number"
        },
        "unit": {
          "type": "string"
        }
      }
    },
    "citation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "citation_id",
        "source_ref",
        "locator",
        "text"
      ],
      "properties": {
        "citation_id": {
          "type": "string"
        },
        "source_ref": {
          "$ref": "#/$defs/nullable_string"
        },
        "locator": {
          "$ref": "#/$defs/nullable_string"
        },
        "text": {
          "$ref": "#/$defs/nullable_string"
        }
      }
    },
    "segment": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "segment_id",
        "ordinal",
        "text",
        "source_start",
        "source_end",
        "citations"
      ],
      "properties": {
        "segment_id": {
          "type": "string"
        },
        "ordinal": {
          "type": "integer"
        },
        "text": {
          "type": "string"
        },
        "source_start": {
          "type": [
            "integer",
            "null"
          ]
        },
        "source_end": {
          "type": [
            "integer",
            "null"
          ]
        },
        "citations": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/citation"
          }
        }
      }
    },
    "document": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "document_id",
        "filename",
        "mime_type",
        "size_bytes",
        "sha256",
        "status",
        "created_at",
        "ready_at",
        "original_path",
        "inline_text",
        "extracted_text",
        "segments"
      ],
      "properties": {
        "document_id": {
          "type": "string"
        },
        "filename": {
          "type": "string"
        },
        "mime_type": {
          "type": "string"
        },
        "size_bytes": {
          "type": [
            "integer",
            "null"
          ]
        },
        "sha256": {
          "$ref": "#/$defs/nullable_string"
        },
        "status": {
          "type": "string"
        },
        "created_at": {
          "$ref": "#/$defs/timestamp"
        },
        "ready_at": {
          "$ref": "#/$defs/timestamp"
        },
        "original_path": {
          "$ref": "#/$defs/nullable_string"
        },
        "inline_text": {
          "$ref": "#/$defs/nullable_string"
        },
        "extracted_text": {
          "$ref": "#/$defs/nullable_string"
        },
        "segments": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/segment"
          }
        }
      }
    },
    "evidence_binding": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "binding_id",
        "source_ref",
        "citation"
      ],
      "properties": {
        "binding_id": {
          "type": "string"
        },
        "source_ref": {
          "$ref": "#/$defs/nullable_string"
        },
        "citation": {
          "$ref": "#/$defs/nullable_string"
        }
      }
    },
    "field_value": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "path",
        "value_json"
      ],
      "properties": {
        "path": {
          "type": "string",
          "description": "Stable dotted field path within the source record."
        },
        "value_json": {
          "type": "string",
          "description": "The field value serialized as valid JSON text."
        }
      }
    },
    "workflow_response": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "step_id",
        "submitted_at",
        "fields"
      ],
      "properties": {
        "step_id": {
          "type": "string"
        },
        "submitted_at": {
          "$ref": "#/$defs/timestamp"
        },
        "fields": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/field_value"
          }
        }
      }
    },
    "workflow_finding": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "finding_id",
        "title",
        "description",
        "severity",
        "status",
        "evidence_binding_ids",
        "fields"
      ],
      "properties": {
        "finding_id": {
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "description": {
          "$ref": "#/$defs/nullable_string"
        },
        "severity": {
          "$ref": "#/$defs/nullable_string"
        },
        "status": {
          "$ref": "#/$defs/nullable_string"
        },
        "evidence_binding_ids": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "fields": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/field_value"
          }
        }
      }
    },
    "workflow": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "workflow_id",
        "workflow_type",
        "status",
        "created_at",
        "updated_at",
        "scope",
        "responses",
        "evidence_bindings",
        "findings",
        "report_ids"
      ],
      "properties": {
        "workflow_id": {
          "type": "string"
        },
        "workflow_type": {
          "type": "string"
        },
        "status": {
          "type": "string"
        },
        "created_at": {
          "$ref": "#/$defs/timestamp"
        },
        "updated_at": {
          "$ref": "#/$defs/timestamp"
        },
        "scope": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/field_value"
          }
        },
        "responses": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/workflow_response"
          }
        },
        "evidence_bindings": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/evidence_binding"
          }
        },
        "findings": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/workflow_finding"
          }
        },
        "report_ids": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "report": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "report_id",
        "workflow_id",
        "format",
        "path",
        "sha256",
        "created_at"
      ],
      "properties": {
        "report_id": {
          "type": "string"
        },
        "workflow_id": {
          "type": "string"
        },
        "format": {
          "type": "string"
        },
        "path": {
          "type": "string"
        },
        "sha256": {
          "type": "string"
        },
        "created_at": {
          "$ref": "#/$defs/timestamp"
        }
      }
    },
    "audit_record": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "record_id",
        "interaction_id",
        "created_at",
        "tool_name",
        "receipt_json",
        "anchor_json",
        "timestamp_json",
        "signature_json",
        "retained_content_json"
      ],
      "properties": {
        "record_id": {
          "type": "string"
        },
        "interaction_id": {
          "$ref": "#/$defs/nullable_string"
        },
        "created_at": {
          "$ref": "#/$defs/timestamp"
        },
        "tool_name": {
          "$ref": "#/$defs/nullable_string"
        },
        "receipt_json": {
          "$ref": "#/$defs/nullable_string",
          "description": "Receipt envelope serialized as valid JSON text."
        },
        "anchor_json": {
          "$ref": "#/$defs/nullable_string",
          "description": "Anchor record serialized as valid JSON text."
        },
        "timestamp_json": {
          "$ref": "#/$defs/nullable_string",
          "description": "Timestamp proof serialized as valid JSON text."
        },
        "signature_json": {
          "$ref": "#/$defs/nullable_string",
          "description": "Signature record serialized as valid JSON text."
        },
        "retained_content_json": {
          "$ref": "#/$defs/nullable_string",
          "description": "Retained interaction content serialized as valid JSON text."
        }
      }
    },
    "setting": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "key",
        "value_json"
      ],
      "properties": {
        "key": {
          "type": "string"
        },
        "value_json": {
          "type": "string",
          "description": "The setting value serialized as valid JSON text."
        }
      }
    },
    "access_assignment": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "principal_id",
        "principal_type",
        "roles"
      ],
      "properties": {
        "principal_id": {
          "type": "string"
        },
        "principal_type": {
          "type": "string"
        },
        "roles": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "configuration_record": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "record_id",
        "type",
        "name",
        "status",
        "configuration_fields"
      ],
      "properties": {
        "record_id": {
          "type": "string"
        },
        "type": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "status": {
          "type": "string"
        },
        "configuration_fields": {
          "type": "array",
          "description": "Customer-created non-secret configuration. Credentials, tokens, private keys, and secret values are omitted.",
          "items": {
            "$ref": "#/$defs/field_value"
          }
        }
      }
    },
    "tenant_configuration": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "settings",
        "access_assignments",
        "connectors",
        "sources"
      ],
      "properties": {
        "settings": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/setting"
          }
        },
        "access_assignments": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/access_assignment"
          }
        },
        "connectors": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/configuration_record"
          }
        },
        "sources": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/configuration_record"
          }
        }
      }
    },
    "manifest_file": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "path",
        "media_type",
        "sha256",
        "size_bytes"
      ],
      "properties": {
        "path": {
          "type": "string"
        },
        "media_type": {
          "type": "string"
        },
        "sha256": {
          "type": "string"
        },
        "size_bytes": {
          "type": "integer"
        }
      }
    },
    "manifest": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "bundle_id",
        "files"
      ],
      "properties": {
        "bundle_id": {
          "type": "string"
        },
        "files": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/manifest_file"
          }
        }
      }
    }
  }
}
