{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "phase6/live_config.schema.json",
  "title": "Phase6LiveConfig",
  "type": "object",
  "required": [
    "env",
    "mode",
    "broker",
    "session",
    "risk_limits",
    "approval",
    "reconciliation",
    "alerts"
  ],
  "properties": {
    "env": {"type": "string", "enum": ["dev", "staging", "prod"]},
    "mode": {"type": "string", "enum": ["dry_run", "paper", "live"]},
    "broker": {
      "type": "object",
      "required": ["name", "account_profile"],
      "properties": {
        "name": {"type": "string"},
        "account_profile": {"type": "string"},
        "stream_enabled": {"type": "boolean", "default": true}
      },
      "additionalProperties": true
    },
    "session": {
      "type": "object",
      "required": ["timezone", "entry_start", "entry_end"],
      "properties": {
        "timezone": {"type": "string"},
        "entry_start": {"type": "string"},
        "entry_end": {"type": "string"},
        "allow_half_day": {"type": "boolean", "default": false}
      },
      "additionalProperties": false
    },
    "risk_limits": {
      "type": "object",
      "required": ["max_positions", "max_daily_loss_pct"],
      "properties": {
        "max_positions": {"type": "integer", "minimum": 1},
        "max_daily_loss_pct": {"type": "number", "minimum": 0},
        "max_sector_positions": {"type": "integer", "minimum": 1},
        "max_gross_exposure_pct": {"type": "number", "minimum": 0}
      },
      "additionalProperties": true
    },
    "approval": {
      "type": "object",
      "required": ["mode"],
      "properties": {
        "mode": {"type": "string", "enum": ["approval_required", "approval_optional", "auto"]},
        "ticket_ttl_seconds": {"type": "integer", "minimum": 1}
      },
      "additionalProperties": false
    },
    "reconciliation": {
      "type": "object",
      "required": ["interval_seconds"],
      "properties": {
        "interval_seconds": {"type": "integer", "minimum": 1},
        "full_sync_on_startup": {"type": "boolean", "default": true}
      },
      "additionalProperties": false
    },
    "alerts": {
      "type": "object",
      "required": ["enabled"],
      "properties": {
        "enabled": {"type": "boolean"},
        "channels": {"type": "array", "items": {"type": "string"}}
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": false
}
