{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://oneisolve.com/schemas/lifeuml-ast-v1.json",
  "title": "LifeUML Abstract Syntax Tree (AST) Specification v1.0",
  "description": "Canonical schema definition for LifeUML declarative mobility and career architecture models.",
  "type": "object",
  "required": ["title", "subject", "destinations", "render_options"],
  "properties": {
    "title": {
      "type": "string",
      "description": "Document title declared via @startlife or title directive",
      "minLength": 1
    },
    "subject": {
      "$ref": "#/definitions/LifeUMLSubject"
    },
    "target": {
      "$ref": "#/definitions/LifeUMLTarget"
    },
    "destinations": {
      "type": "array",
      "description": "Candidate destination jurisdictions evaluated by the engine",
      "items": {
        "$ref": "#/definitions/LifeUMLDestination"
      },
      "minItems": 1
    },
    "constraints": {
      "type": "object",
      "properties": {
        "max_acceptable_tax_rate": { "type": "number", "minimum": 0, "maximum": 1 },
        "require_schengen_mobility": { "type": "boolean" },
        "internet_speed_min_mbps": { "type": "number", "minimum": 0 }
      }
    },
    "render_options": {
      "type": "object",
      "properties": {
        "radar": { "type": "boolean" },
        "runway": { "type": "boolean" },
        "roadmap": { "type": "boolean" }
      },
      "required": ["radar", "runway"]
    },
    "milestones": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/LifeUMLMilestone"
      }
    }
  },
  "definitions": {
    "LifeUMLSubject": {
      "type": "object",
      "required": ["name", "citizenship", "capital"],
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_]+$",
          "description": "Identifier token for the individual"
        },
        "age": {
          "type": "integer",
          "minimum": 16,
          "maximum": 120
        },
        "citizenship": {
          "type": "string",
          "pattern": "^[A-Z]{2}$",
          "description": "ISO 3166-1 alpha-2 nationality code"
        },
        "psychometrics": {
          "type": "object",
          "properties": {
            "mbti": { "type": "string" },
            "big5": {
              "type": "object",
              "required": ["O", "C", "E", "A", "N"],
              "properties": {
                "O": { "type": "number", "minimum": 0, "maximum": 1, "description": "Openness" },
                "C": { "type": "number", "minimum": 0, "maximum": 1, "description": "Conscientiousness" },
                "E": { "type": "number", "minimum": 0, "maximum": 1, "description": "Extraversion" },
                "A": { "type": "number", "minimum": 0, "maximum": 1, "description": "Agreeableness" },
                "N": { "type": "number", "minimum": 0, "maximum": 1, "description": "Neuroticism" }
              }
            },
            "riasec": {
              "type": "object",
              "properties": {
                "R": { "type": "number", "minimum": 0, "maximum": 1 },
                "I": { "type": "number", "minimum": 0, "maximum": 1 },
                "A": { "type": "number", "minimum": 0, "maximum": 1 },
                "S": { "type": "number", "minimum": 0, "maximum": 1 },
                "E": { "type": "number", "minimum": 0, "maximum": 1 },
                "C": { "type": "number", "minimum": 0, "maximum": 1 }
              }
            },
            "risk_tolerance": {
              "type": "number",
              "minimum": 0,
              "maximum": 1
            }
          }
        },
        "capital": {
          "type": "object",
          "required": ["liquid_savings", "monthly_remote_income"],
          "properties": {
            "liquid_savings": { "type": "number", "minimum": 0, "description": "Amount in USD" },
            "monthly_remote_income": { "type": "number", "minimum": 0, "description": "Amount in USD per month" },
            "income_type": {
              "type": "string",
              "enum": ["ContractRemote", "SalariedRemote", "PassiveInvestment", "FreelanceClient", "SavingsRunway"]
            },
            "tax_residency_current": { "type": "string" }
          }
        },
        "ax_skills": {
          "type": "object",
          "properties": {
            "llm_orchestration": { "type": "number", "minimum": 0, "maximum": 1 },
            "autonomous_agents": { "type": "number", "minimum": 0, "maximum": 1 },
            "fullstack_web": { "type": "number", "minimum": 0, "maximum": 1 },
            "data_automation": { "type": "number", "minimum": 0, "maximum": 1 }
          }
        }
      }
    },
    "LifeUMLTarget": {
      "type": "object",
      "required": ["name", "type", "timeframe_months", "min_runway_months"],
      "properties": {
        "name": { "type": "string" },
        "type": { "type": "string" },
        "focus": { "type": "string" },
        "timeframe_months": { "type": "integer", "minimum": 1 },
        "min_runway_months": { "type": "integer", "minimum": 1 }
      }
    },
    "LifeUMLDestination": {
      "type": "object",
      "required": ["countryCode", "visa", "statutory_threshold_usd", "col_monthly_usd", "tax_drag_rate"],
      "properties": {
        "countryCode": { "type": "string", "pattern": "^[A-Z]{2}$" },
        "name": { "type": "string" },
        "visa": { "type": "string" },
        "statutory_threshold_usd": { "type": "number", "minimum": 0 },
        "col_monthly_usd": { "type": "number", "minimum": 0 },
        "schengen": { "type": "boolean" },
        "tax_drag_rate": { "type": "number", "minimum": 0, "maximum": 0.6 },
        "ax_hub_score": { "type": "number", "minimum": 0, "maximum": 100 }
      }
    },
    "LifeUMLMilestone": {
      "type": "object",
      "required": ["title", "target_date"],
      "properties": {
        "title": { "type": "string" },
        "target_date": { "type": "string" },
        "status": { "type": "string", "enum": ["pending", "in_progress", "completed"] }
      }
    }
  }
}
