{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://uniohos.github.io/docs/schemas/device.schema.json",
  "title": "UniOHOS Declarative Device Porting Recipe (device.yaml)",
  "type": "object",
  "required": [
    "schema_version",
    "device",
    "soc",
    "compatibility",
    "engineering_stage",
    "bootloader",
    "kernel",
    "display",
    "gpu",
    "sidecar",
    "selinux",
    "power",
    "safety",
    "byof_inputs"
  ],
  "properties": {
    "schema_version": { "type": "string", "const": "1.0" },
    "device": {
      "type": "object",
      "required": ["vendor", "model", "codename", "form_factor", "arch"],
      "properties": {
        "vendor": { "type": "string" },
        "model": { "type": "string" },
        "codename": { "type": "string", "pattern": "^[a-z0-9_-]+$" },
        "model_number": { "type": "string" },
        "form_factor": { "type": "string", "enum": ["phone", "tablet", "sbc", "laptop"] },
        "arch": { "type": "string", "enum": ["arm64", "x86_64"] }
      }
    },
    "soc": {
      "type": "object",
      "required": ["family", "bsp_repo", "kernel_repo"],
      "properties": {
        "family": { "type": "string" },
        "cpu_clusters": { "type": "string" },
        "bsp_repo": { "type": "string" },
        "bsp_profile": { "type": "string" },
        "device_overlay_repo": { "type": "string" },
        "kernel_repo": { "type": "string" }
      }
    },
    "compatibility": {
      "type": "object",
      "required": ["core_min_version", "builder_min_version"],
      "properties": {
        "core_min_version": { "type": "string" },
        "builder_min_version": { "type": "string" }
      }
    },
    "engineering_stage": {
      "type": "string",
      "enum": ["stage-0", "stage-1", "stage-2", "stage-3", "stage-4"]
    },
    "bootloader": {
      "type": "object",
      "required": ["ab_slots"],
      "properties": {
        "official_unlock_required": { "type": "boolean" },
        "ab_slots": { "type": "boolean" },
        "target_slot": { "type": "string", "enum": ["a", "b"] }
      }
    },
    "kernel": {
      "type": "object",
      "required": ["version", "branch", "tag", "custom_kmods"],
      "properties": {
        "version": { "type": "string" },
        "branch": { "type": "string" },
        "tag": { "type": "string" },
        "dtbo_target": { "type": "string" },
        "lz4p_ultra": { "type": "boolean" },
        "custom_kmods": { "type": "array", "items": { "type": "string" } }
      }
    },
    "display": {
      "type": "object",
      "required": ["driver", "resolution", "max_refresh_hz", "dpi"],
      "properties": {
        "driver": { "type": "string" },
        "resolution": { "type": "string" },
        "max_refresh_hz": { "type": "integer", "minimum": 30 },
        "ltpo": { "type": "boolean" },
        "dpi": { "type": "integer", "minimum": 72 },
        "dp_alt_mode": { "type": "string" }
      }
    },
    "gpu": {
      "type": "object",
      "required": ["hardware", "primary_engine", "fallback_mesa_driver"],
      "properties": {
        "hardware": { "type": "string" },
        "primary_engine": { "type": "string" },
        "tpidr_el0_trampoline": { "type": "boolean" },
        "fallback_mesa_driver": {
          "type": "string",
          "enum": ["panvk", "panfrost", "turnip", "freedreno", "radv", "anv", "iris", "llvmpipe", "zink"]
        }
      }
    },
    "sidecar": {
      "type": "object",
      "required": ["enabled", "services"],
      "properties": {
        "enabled": { "type": "boolean" },
        "bionic_api_level": { "type": "integer" },
        "services": { "type": "array", "items": { "type": "string" } }
      }
    },
    "selinux": {
      "type": "object",
      "required": ["target_mode", "zero_neverallow"],
      "properties": {
        "target_mode": { "type": "string", "enum": ["enforcing", "permissive"] },
        "enforcement_model": { "type": "string", "enum": ["day-0", "two-stage", "permissive"] },
        "two_stage_boot_done": { "type": "boolean" },
        "zero_neverallow": { "type": "boolean", "const": true }
      }
    },
    "power": {
      "type": "object",
      "required": ["standby_cpu_budget_pct"],
      "properties": {
        "charge_bypass_percent": { "type": "integer", "minimum": 50, "maximum": 100 },
        "standby_cpu_budget_pct": { "type": "number", "maximum": 5.0 }
      }
    },
    "safety": {
      "type": "object",
      "properties": {
        "oled_bri_zero_guard": { "type": "boolean" },
        "untouched_bootchain_partitions": { "type": "array", "items": { "type": "string" } },
        "ufs_readonly_partitions": { "type": "array", "items": { "type": "string" } }
      }
    },
    "byof_inputs": {
      "type": "object",
      "required": ["zero_remote_blobs", "local_partitions"],
      "properties": {
        "zero_remote_blobs": { "type": "boolean", "const": true },
        "local_partitions": { "type": "array", "minItems": 0, "items": { "type": "string" } }
      }
    }
  }
}
