{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "ECC install state",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "installedAt",
    "target",
    "request",
    "resolution",
    "source",
    "operations"
  ],
  "properties": {
    "schemaVersion": {
      "type": "string",
      "const": "ecc.install.v1"
    },
    "installedAt": {
      "type": "string",
      "minLength": 1
    },
    "lastValidatedAt": {
      "type": "string",
      "minLength": 1
    },
    "target": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "root",
        "installStatePath"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "target": {
          "type": "string",
          "minLength": 1
        },
        "kind": {
          "type": "string",
          "enum": [
            "home",
            "project"
          ]
        },
        "root": {
          "type": "string",
          "minLength": 1
        },
        "installStatePath": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "request": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "profile",
        "modules",
        "includeComponents",
        "excludeComponents",
        "legacyLanguages",
        "legacyMode"
      ],
      "properties": {
        "profile": {
          "type": [
            "string",
            "null"
          ]
        },
        "modules": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "includeComponents": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "excludeComponents": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "legacyLanguages": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "legacyMode": {
          "type": "boolean"
        },
        "hookConsent": {
          "enum": [
            "enabled",
            "declined",
            null
          ]
        }
      }
    },
    "resolution": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "selectedModules",
        "skippedModules"
      ],
      "properties": {
        "selectedModules": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "skippedModules": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "repoVersion",
        "repoCommit",
        "manifestVersion"
      ],
      "properties": {
        "repoVersion": {
          "type": [
            "string",
            "null"
          ]
        },
        "repoCommit": {
          "type": [
            "string",
            "null"
          ]
        },
        "manifestVersion": {
          "type": "integer",
          "minimum": 1
        }
      }
    },
    "operations": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true,
        "required": [
          "kind",
          "moduleId",
          "sourceRelativePath",
          "destinationPath",
          "strategy",
          "ownership",
          "scaffoldOnly"
        ],
        "properties": {
          "kind": {
            "type": "string",
            "minLength": 1
          },
          "moduleId": {
            "type": "string",
            "minLength": 1
          },
          "sourceRelativePath": {
            "type": "string",
            "minLength": 1
          },
          "destinationPath": {
            "type": "string",
            "minLength": 1
          },
          "strategy": {
            "type": "string",
            "minLength": 1
          },
          "ownership": {
            "type": "string",
            "minLength": 1
          },
          "scaffoldOnly": {
            "type": "boolean"
          },
          "contentSha256": {
            "type": "string",
            "pattern": "^[a-fA-F0-9]{64}$"
          },
          "managedHooks": {
            "type": "object",
            "minProperties": 1,
            "propertyNames": {
              "type": "string",
              "pattern": "\\S"
            },
            "additionalProperties": {
              "type": "array",
              "minItems": 1,
              "items": {
                "type": "object",
                "required": ["id", "hooks"],
                "properties": {
                  "id": {
                    "type": "string",
                    "pattern": "\\S"
                  }
                }
              }
            }
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "kind": { "const": "update-claude-settings" }
              }
            },
            "then": {
              "required": ["managedHooks"],
              "properties": {
                "moduleId": { "const": "hooks-runtime" },
                "sourceRelativePath": { "const": "hooks/hooks.json" }
              }
            }
          }
        ]
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "operations": {
            "contains": {
              "type": "object",
              "properties": {
                "kind": { "const": "update-claude-settings" }
              },
              "required": ["kind"]
            }
          }
        }
      },
      "then": {
        "properties": {
          "target": {
            "properties": {
              "target": { "enum": ["claude", "claude-project"] }
            },
            "required": ["target"]
          }
        }
      }
    }
  ]
}
