{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://veydrin.codeberg.page/protocols/vfds/vfds-v1.0.schema.json",
  "title": "VFDS v1.0 — Veydrin Financial Data Standard",
  "description": "Schema for household financial sovereignty and trust lifecycle data exports. Builds on VODS v1.0.",
  "type": "object",
  "required": ["vfds_version", "exported_at", "app_version", "vault", "flow", "position", "debt", "wealth", "protection", "goals", "milestones", "notifications", "settings"],
  "properties": {
    "vfds_version": { "type": "string" },
    "exported_at": { "type": "string", "format": "date-time" },
    "app_version": { "type": "string" },
    "vault": { "$ref": "#/$defs/Vault" },
    "flow": { "$ref": "#/$defs/Flow" },
    "position": { "$ref": "#/$defs/Position" },
    "debt": { "$ref": "#/$defs/Debt" },
    "wealth": { "$ref": "#/$defs/Wealth" },
    "protection": { "$ref": "#/$defs/Protection" },
    "goals": { "$ref": "#/$defs/Goals" },
    "milestones": { "type": "array", "items": { "$ref": "#/$defs/Milestone" } },
    "notifications": { "type": "array", "items": { "$ref": "#/$defs/Notification" } },
    "settings": { "$ref": "#/$defs/Settings" }
  },
  "additionalProperties": true,
  "$defs": {
    "Vault": {
      "type": "object",
      "required": ["id", "name", "tier", "base_currency_code", "created_at", "updated_at"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "name": { "type": "string" },
        "tier": { "type": "string", "enum": ["solo", "household", "trust"] },
        "base_currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "trust_type": { "type": "string", "enum": ["living_trust", "family_trust", "business_trust", "nonprofit_trust"] },
        "lifecycle_stage": { "type": "string", "enum": ["creation", "active_revocable", "conversion", "active_irrevocable", "succession", "legacy", "continuance"] },
        "created_at": { "type": "string", "format": "date-time" },
        "updated_at": { "type": "string", "format": "date-time" },
        "members": { "type": "array", "items": { "$ref": "#/$defs/Member" } },
        "role_permissions": { "type": "array", "items": { "$ref": "#/$defs/RolePermission" } },
        "documents": { "type": "array", "items": { "$ref": "#/$defs/Document" } },
        "ownership_entities": { "type": "array", "items": { "$ref": "#/$defs/OwnershipEntity" } }
      },
      "additionalProperties": false
    },
    "Member": {
      "type": "object",
      "required": ["id", "name", "role", "joined_at", "is_owner"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "name": { "type": "string" },
        "role": { "type": "string", "enum": ["trustor", "trustee", "co_trustee", "partner", "steward", "beneficiary", "observer", "successor_trustee", "attorney", "accountant", "minor"] },
        "joined_at": { "type": "string", "format": "date-time" },
        "avatar_initials": { "type": "string" },
        "is_owner": { "type": "boolean" }
      },
      "additionalProperties": false
    },
    "RolePermission": {
      "type": "object",
      "required": ["role", "layer_permissions"],
      "properties": {
        "role": { "type": "string", "enum": ["trustor", "trustee", "co_trustee", "partner", "steward", "beneficiary", "observer", "successor_trustee", "attorney", "accountant", "minor"] },
        "layer_permissions": {
          "type": "object",
          "properties": {
            "flow": { "$ref": "#/$defs/PermissionLevel" },
            "position": { "$ref": "#/$defs/PermissionLevel" },
            "debt": { "$ref": "#/$defs/PermissionLevel" },
            "wealth": { "$ref": "#/$defs/PermissionLevel" },
            "protection": { "$ref": "#/$defs/PermissionLevel" },
            "documents": { "$ref": "#/$defs/PermissionLevel" },
            "milestones": { "$ref": "#/$defs/PermissionLevel" },
            "members": { "$ref": "#/$defs/PermissionLevel" },
            "settings": { "$ref": "#/$defs/PermissionLevel" },
            "trust_lifecycle": { "$ref": "#/$defs/PermissionLevel" }
          },
          "additionalProperties": false
        },
        "can_invite_members": { "type": "boolean" },
        "can_export_data": { "type": "boolean" },
        "can_initiate_conversion": { "type": "boolean" },
        "can_trigger_succession": { "type": "boolean" },
        "can_modify_roles": { "type": "boolean" }
      },
      "additionalProperties": false
    },
    "PermissionLevel": {
      "type": "string",
      "enum": ["none", "read_only", "read_write", "admin"]
    },
    "Document": {
      "type": "object",
      "required": ["id", "name", "category", "size_bytes", "added_at", "is_locked"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "name": { "type": "string" },
        "category": { "type": "string", "enum": ["trust_instrument", "will_testament", "insurance", "property_deed", "operating_agreement", "power_of_attorney", "tax_record", "other"] },
        "size_bytes": { "type": "integer", "minimum": 0 },
        "notes": { "type": "string" },
        "added_at": { "type": "string", "format": "date-time" },
        "expires_at": { "type": "string", "format": "date-time" },
        "is_locked": { "type": "boolean" }
      },
      "additionalProperties": false
    },
    "OwnershipEntity": {
      "type": "object",
      "required": ["id", "name", "type", "created_at"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "name": { "type": "string" },
        "type": { "type": "string", "enum": ["trust", "llc", "brokerage", "bank_account", "real_estate", "vehicle", "insurance", "retirement_account", "crypto", "business_interest", "personal_property", "beneficiary", "other"] },
        "parent_id": { "type": ["string", "null"], "format": "uuid" },
        "value": { "type": "string" },
        "currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "notes": { "type": "string" },
        "created_at": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": false
    },
    "Flow": {
      "type": "object",
      "properties": {
        "transactions": { "type": "array", "items": { "$ref": "#/$defs/Transaction" } },
        "receipts": { "type": "array", "items": { "$ref": "#/$defs/Receipt" } },
        "subscriptions": { "type": "array", "items": { "$ref": "#/$defs/Subscription" } },
        "donations": { "type": "array", "items": { "$ref": "#/$defs/Donation" } },
        "budget_categories": { "type": "array", "items": { "$ref": "#/$defs/BudgetCategory" } },
        "recurring_transactions": { "type": "array", "items": { "$ref": "#/$defs/RecurringTransaction" } },
        "bill_reminders": { "type": "array", "items": { "$ref": "#/$defs/BillReminder" } }
      },
      "additionalProperties": false
    },
    "Transaction": {
      "type": "object",
      "required": ["id", "description", "amount", "currency_code", "type", "date", "created_at"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "description": { "type": "string" },
        "amount": { "type": "string" },
        "currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "type": { "type": "string", "enum": ["income", "expense"] },
        "category_id": { "type": "string", "format": "uuid" },
        "date": { "type": "string", "format": "date-time" },
        "member_id": { "type": "string", "format": "uuid" },
        "created_at": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": false
    },
    "Receipt": {
      "type": "object",
      "required": ["id", "image_path", "captured_at", "currency_code"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "image_path": { "type": "string" },
        "captured_at": { "type": "string", "format": "date-time" },
        "amount": { "type": "string" },
        "merchant": { "type": "string" },
        "category": { "type": "string" },
        "notes": { "type": "string" },
        "linked_transaction_id": { "type": "string", "format": "uuid" },
        "currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "ocr_text": { "type": "string" }
      },
      "additionalProperties": false
    },
    "Subscription": {
      "type": "object",
      "required": ["id", "name", "monthly_cost", "currency_code", "is_active", "created_at"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "name": { "type": "string" },
        "monthly_cost": { "type": "string" },
        "currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "category": { "type": "string" },
        "frequency": { "type": "string", "enum": ["weekly", "biweekly", "monthly", "quarterly", "yearly"] },
        "next_due_date": { "type": "string", "format": "date-time" },
        "icon": { "type": "string" },
        "is_active": { "type": "boolean" },
        "created_at": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": false
    },
    "Donation": {
      "type": "object",
      "required": ["id", "organization", "amount", "currency_code", "recurring", "created_at"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "organization": { "type": "string" },
        "amount": { "type": "string" },
        "currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "frequency": { "type": "string", "enum": ["weekly", "biweekly", "monthly", "quarterly", "yearly"] },
        "icon": { "type": "string" },
        "recurring": { "type": "boolean" },
        "created_at": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": false
    },
    "BudgetCategory": {
      "type": "object",
      "required": ["id", "name", "budgeted", "spent"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "name": { "type": "string" },
        "budgeted": { "type": "string" },
        "spent": { "type": "string" },
        "rollover": { "type": "boolean" },
        "currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "icon": { "type": "string" },
        "color": { "type": "string" }
      },
      "additionalProperties": false
    },
    "RecurringTransaction": {
      "type": "object",
      "required": ["id", "name", "amount", "is_income", "frequency", "category", "next_due_date", "is_active"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "name": { "type": "string" },
        "amount": { "type": "string" },
        "currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "is_income": { "type": "boolean" },
        "frequency": { "type": "string", "enum": ["weekly", "biweekly", "monthly", "quarterly", "yearly"] },
        "category": { "type": "string" },
        "next_due_date": { "type": "string", "format": "date-time" },
        "is_active": { "type": "boolean" }
      },
      "additionalProperties": false
    },
    "BillReminder": {
      "type": "object",
      "required": ["id", "name", "amount", "currency_code", "frequency", "due_day", "autopay", "is_active", "created_at"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "name": { "type": "string" },
        "amount": { "type": "string" },
        "currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "frequency": { "type": "string", "enum": ["weekly", "biweekly", "monthly", "quarterly", "semiannual", "annual"] },
        "due_day": { "type": "integer", "minimum": 1, "maximum": 31 },
        "autopay": { "type": "boolean" },
        "category": { "type": "string" },
        "is_active": { "type": "boolean" },
        "created_at": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": false
    },
    "Position": {
      "type": "object",
      "properties": {
        "assets": { "type": "array", "items": { "$ref": "#/$defs/Asset" } },
        "liabilities": { "type": "array", "items": { "$ref": "#/$defs/Liability" } },
        "net_worth_snapshots": { "type": "array", "items": { "$ref": "#/$defs/NetWorthSnapshot" } }
      },
      "additionalProperties": false
    },
    "Asset": {
      "type": "object",
      "required": ["id", "name", "type", "value", "currency_code", "last_updated"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "name": { "type": "string" },
        "type": { "type": "string", "enum": ["cash", "savings", "investment", "retirement", "real_estate", "vehicle", "personal_property", "other"] },
        "value": { "type": "string" },
        "loan_balance": { "type": "string" },
        "currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "ownership_entity_id": { "type": "string", "format": "uuid" },
        "last_updated": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": false
    },
    "Liability": {
      "type": "object",
      "required": ["id", "name", "type", "balance", "interest_rate", "minimum_payment", "currency_code", "last_updated"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "name": { "type": "string" },
        "type": { "type": "string", "enum": ["mortgage", "auto_loan", "student_loan", "credit_card", "personal_loan", "medical_debt", "other"] },
        "balance": { "type": "string" },
        "interest_rate": { "type": "string" },
        "minimum_payment": { "type": "string" },
        "currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "debt_account_id": { "type": "string", "format": "uuid" },
        "last_updated": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": false
    },
    "NetWorthSnapshot": {
      "type": "object",
      "required": ["id", "net_worth", "total_assets", "total_liabilities", "recorded_at"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "net_worth": { "type": "string" },
        "total_assets": { "type": "string" },
        "total_liabilities": { "type": "string" },
        "recorded_at": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": false
    },
    "Debt": {
      "type": "object",
      "properties": {
        "accounts": { "type": "array", "items": { "$ref": "#/$defs/DebtAccount" } },
        "payoff_strategy": { "type": "string", "enum": ["avalanche", "snowball", "custom"] }
      },
      "additionalProperties": false
    },
    "DebtAccount": {
      "type": "object",
      "required": ["id", "name", "debt_type", "balance", "interest_rate", "minimum_payment", "currency_code"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "name": { "type": "string" },
        "debt_type": { "type": "string", "enum": ["credit_card", "mortgage", "auto_loan", "student_loan", "personal_loan", "home_equity", "medical", "business_loan", "tax_debt", "other"] },
        "balance": { "type": "string" },
        "interest_rate": { "type": "string" },
        "minimum_payment": { "type": "string" },
        "credit_limit": { "type": "string" },
        "due_day": { "type": "integer", "minimum": 1, "maximum": 31 },
        "is_revolving": { "type": "boolean" },
        "currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" }
      },
      "additionalProperties": false
    },
    "Wealth": {
      "type": "object",
      "properties": {
        "holdings": { "type": "array", "items": { "$ref": "#/$defs/Holding" } },
        "watchlist": { "type": "array", "items": { "$ref": "#/$defs/WatchlistItem" } }
      },
      "additionalProperties": false
    },
    "Holding": {
      "type": "object",
      "required": ["id", "name", "asset_class", "shares", "price_per_share", "cost_basis", "currency_code"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "name": { "type": "string" },
        "ticker": { "type": "string" },
        "asset_class": { "type": "string", "enum": ["stock", "etf", "mutual_fund", "crypto", "bond", "real_estate", "private_equity", "annuity", "retirement_account", "other"] },
        "shares": { "type": "string" },
        "price_per_share": { "type": "string" },
        "cost_basis": { "type": "string" },
        "currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "ownership_entity_id": { "type": "string", "format": "uuid" },
        "dividend_per_share": { "type": "string" },
        "dividend_frequency": { "type": "string", "enum": ["monthly", "quarterly", "semiannual", "annual", "irregular"] },
        "notes": { "type": "string" }
      },
      "additionalProperties": false
    },
    "WatchlistItem": {
      "type": "object",
      "required": ["id", "ticker", "name", "added_at"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "ticker": { "type": "string" },
        "name": { "type": "string" },
        "sector": { "type": "string" },
        "price_target": { "type": "string" },
        "current_price": { "type": "string" },
        "currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "price_updated_at": { "type": "string", "format": "date-time" },
        "notes": { "type": "string" },
        "added_at": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": false
    },
    "Protection": {
      "type": "object",
      "properties": {
        "policies": { "type": "array", "items": { "$ref": "#/$defs/Policy" } },
        "beneficiary_designations": { "type": "array", "items": { "$ref": "#/$defs/BeneficiaryEntry" } }
      },
      "additionalProperties": false
    },
    "Policy": {
      "type": "object",
      "required": ["id", "provider", "type", "premium", "premium_frequency", "coverage_amount", "deductible"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "provider": { "type": "string" },
        "type": { "type": "string", "enum": ["health", "life", "auto", "homeowners", "renters", "umbrella", "disability", "long_term_care", "dental", "vision", "other"] },
        "premium": { "type": "string" },
        "premium_frequency": { "type": "string" },
        "coverage_amount": { "type": "string" },
        "deductible": { "type": "string" },
        "currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "ownership_entity_id": { "type": "string", "format": "uuid" },
        "renewal_date": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": false
    },
    "BeneficiaryEntry": {
      "type": "object",
      "required": ["id", "account_name", "account_type", "beneficiary", "allocation", "tier", "created_at"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "account_name": { "type": "string" },
        "account_type": { "type": "string" },
        "beneficiary": { "type": "string" },
        "allocation": { "type": "string" },
        "tier": { "type": "string", "enum": ["primary", "contingent"] },
        "last_reviewed": { "type": "string", "format": "date-time" },
        "issue": { "type": "string" },
        "created_at": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": false
    },
    "Goals": {
      "type": "object",
      "properties": {
        "financial_goals": { "type": "array", "items": { "$ref": "#/$defs/Goal" } },
        "life_events": { "type": "array", "items": { "$ref": "#/$defs/LifeEvent" } }
      },
      "additionalProperties": false
    },
    "Goal": {
      "type": "object",
      "required": ["id", "name", "target_amount", "current_amount", "currency_code", "category", "created_at", "is_completed"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "name": { "type": "string" },
        "target_amount": { "type": "string" },
        "current_amount": { "type": "string" },
        "currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "category": { "type": "string", "enum": ["emergency", "house", "retirement", "education", "vehicle", "travel", "custom"] },
        "deadline": { "type": "string", "format": "date-time" },
        "created_at": { "type": "string", "format": "date-time" },
        "is_completed": { "type": "boolean" }
      },
      "additionalProperties": false
    },
    "LifeEvent": {
      "type": "object",
      "required": ["id", "name", "currency_code", "active", "created_at"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "name": { "type": "string" },
        "target_date": { "type": "string", "format": "date-time" },
        "estimated_cost": { "type": "string" },
        "current_saved": { "type": "string" },
        "currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "icon": { "type": "string" },
        "color": { "type": "string" },
        "active": { "type": "boolean" },
        "created_at": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": false
    },
    "Milestone": {
      "type": "object",
      "required": ["id", "title", "description", "target_amount", "current_amount", "status", "currency_code"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "title": { "type": "string" },
        "description": { "type": "string" },
        "target_amount": { "type": "string" },
        "current_amount": { "type": "string" },
        "target_date": { "type": "string", "format": "date-time" },
        "status": { "type": "string", "enum": ["upcoming", "in_progress", "achieved"] },
        "currency_code": { "type": "string", "pattern": "^[A-Z]{3}$" }
      },
      "additionalProperties": false
    },
    "Notification": {
      "type": "object",
      "required": ["id", "title", "body", "type", "created_at", "is_read"],
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "title": { "type": "string" },
        "body": { "type": "string" },
        "type": { "type": "string", "enum": ["info", "warning", "milestone", "security", "sync"] },
        "created_at": { "type": "string", "format": "date-time" },
        "is_read": { "type": "boolean" },
        "route": { "type": "string" }
      },
      "additionalProperties": false
    },
    "Settings": {
      "type": "object",
      "properties": {
        "base_currency_code": { "type": "string", "pattern": "^[A-Z]{3}$", "default": "USD" },
        "show_currency_symbols": { "type": "boolean", "default": true },
        "compact_large_numbers": { "type": "boolean", "default": false },
        "biometrics_enabled": { "type": "boolean", "default": false },
        "prevent_screenshots": { "type": "boolean", "default": true },
        "auto_lock_seconds": { "type": "integer", "default": 60 }
      },
      "additionalProperties": false
    }
  }
}
