{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/realpkuasule/harness-automation/main/docs/api/worktree-delivery-v1.schema.json",
  "title": "Harness Worktree Delivery Configuration v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "mode",
    "maxPersistentWorktrees",
    "leaseTtlHours",
    "reviewTtlMinutes",
    "remoteBranchRetentionDays",
    "remoteBranchDeletion",
    "provider"
  ],
  "dependentRequired": {
    "allowedRoots": ["protectedRoots"],
    "protectedRoots": ["allowedRoots"]
  },
  "properties": {
    "schemaVersion": {
      "const": "1.0"
    },
    "mode": {
      "enum": ["audit-only", "enforced"]
    },
    "managementBranch": {
      "type": "string",
      "minLength": 1,
      "description": "Portable branch selector for the single persistent management checkout."
    },
    "maxPersistentWorktrees": {
      "type": "integer",
      "minimum": 1,
      "description": "New configurations default to 2; explicit existing values are preserved."
    },
    "leaseTtlHours": {
      "type": "integer",
      "minimum": 1,
      "description": "New configurations default to 72 hours; explicit existing values are preserved."
    },
    "reviewTtlMinutes": {
      "type": "integer",
      "minimum": 1
    },
    "remoteBranchRetentionDays": {
      "type": "integer",
      "minimum": 1,
      "description": "Read-only stale feature-branch audit age; management branches are excluded and new configurations default to 1 day."
    },
    "allowedRoots": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "deprecated": true,
      "description": "Legacy embedded host paths. New plans write these to the Git-common-dir host binding instead.",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "protectedRoots": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "deprecated": true,
      "description": "Legacy embedded host paths. New plans write these to the Git-common-dir host binding instead.",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "remoteBranchDeletion": {
      "type": "boolean",
      "description": "When true, close requires merge proof and deletes the exact local and remote feature refs with SHA compare-and-swap. New configurations default to true."
    },
    "provider": {
      "$ref": "#/$defs/provider"
    }
  },
  "$defs": {
    "provider": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind"],
      "properties": {
        "kind": {
          "enum": ["none", "github", "gitlab", "jira"]
        },
        "repository": {
          "type": "string",
          "minLength": 1
        },
        "project": {
          "type": "object",
          "additionalProperties": false,
          "required": ["owner", "number", "statusField", "doneValues"],
          "properties": {
            "owner": {
              "type": "string",
              "minLength": 1
            },
            "number": {
              "type": "integer",
              "minimum": 1
            },
            "statusField": {
              "type": "string",
              "minLength": 1
            },
            "doneValues": {
              "type": "array",
              "minItems": 1,
              "uniqueItems": true,
              "items": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "const": "none"
              }
            }
          },
          "then": {
            "not": {
              "required": ["repository"]
            }
          },
          "else": {
            "required": ["repository"]
          }
        }
      ]
    }
  }
}
