{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://anolishq.github.io/schemas/anolis/machine/machine-profile.schema.json",
  "title": "Anolis Machine Profile Manifest",
  "description": "Contract for machine package manifests under config/<machine_id>/machine-profile.yaml.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "machine_id",
    "display_name",
    "runtime_profiles",
    "providers",
    "contracts",
    "compatibility"
  ],
  "properties": {
    "schema_version": {
      "type": "integer",
      "const": 1
    },
    "machine_id": {
      "type": "string",
      "minLength": 1,
      "pattern": "^[a-z0-9][a-z0-9-]*$"
    },
    "display_name": {
      "type": "string",
      "minLength": 1
    },
    "runtime_profiles": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "manual"
      ],
      "properties": {
        "manual": {
          "$ref": "#/definitions/relativePath"
        },
        "telemetry": {
          "$ref": "#/definitions/relativePath"
        },
        "automation": {
          "$ref": "#/definitions/relativePath"
        },
        "full": {
          "$ref": "#/definitions/relativePath"
        }
      }
    },
    "providers": {
      "type": "object",
      "minProperties": 1,
      "propertyNames": {
        "pattern": "^[A-Za-z0-9_-]+$"
      },
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "config"
        ],
        "properties": {
          "config": {
            "$ref": "#/definitions/relativePath"
          },
          "notes": {
            "type": "string"
          }
        }
      }
    },
    "behaviors": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/relativePath"
      },
      "uniqueItems": true
    },
    "validation": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "expected_providers": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]+$"
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "check_http_script": {
          "$ref": "#/definitions/relativePath"
        }
      }
    },
    "contracts": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "runtime_config_baseline",
        "runtime_http_baseline"
      ],
      "properties": {
        "runtime_config_baseline": {
          "$ref": "#/definitions/relativePath"
        },
        "runtime_http_baseline": {
          "$ref": "#/definitions/relativePath"
        }
      }
    },
    "compatibility": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "runtime",
        "providers"
      ],
      "properties": {
        "runtime": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "config_contract",
            "http_contract"
          ],
          "properties": {
            "config_contract": {
              "type": "string"
            },
            "http_contract": {
              "type": "string"
            },
            "notes": {
              "type": "string"
            }
          }
        },
        "providers": {
          "type": "object",
          "minProperties": 1,
          "propertyNames": {
            "pattern": "^[A-Za-z0-9_-]+$"
          },
          "additionalProperties": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "strategy",
              "version"
            ],
            "properties": {
              "strategy": {
                "type": "string",
                "enum": [
                  "local-build",
                  "pinned-ref",
                  "semver-range"
                ]
              },
              "version": {
                "type": "string",
                "minLength": 1
              },
              "notes": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  },
  "definitions": {
    "relativePath": {
      "type": "string",
      "minLength": 1
    }
  }
}
