{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://caddi.build/schema/v1/caddi.json",
  "title": "caddi.json",
  "description": "Project-level configuration for a Caddi-managed repository. Read by the @caddi/cli; auto-populated by `caddi init` and `caddi link`.",
  "type": "object",
  "additionalProperties": false,
  "required": ["workspace", "project", "framework", "environments"],
  "properties": {
    "$schema": {
      "type": "string",
      "format": "uri",
      "description": "Reference to this JSON Schema for editor autocompletion."
    },
    "workspace": {
      "type": "string",
      "minLength": 1,
      "pattern": "^[a-z0-9][a-z0-9-]{0,62}$",
      "description": "Workspace slug on caddi.build."
    },
    "project": {
      "type": "string",
      "minLength": 1,
      "description": "Project name within the workspace."
    },
    "framework": {
      "type": "string",
      "enum": ["next", "astro", "static", "unknown"],
      "description": "Framework used by this project. Determines build defaults."
    },
    "environments": {
      "type": "object",
      "additionalProperties": false,
      "required": ["production"],
      "description": "Branch mapping for each environment. Production is required.",
      "properties": {
        "production": { "$ref": "#/$defs/environment" },
        "staging": { "$ref": "#/$defs/environment" },
        "development": { "$ref": "#/$defs/environment" }
      }
    },
    "forms": {
      "type": "array",
      "description": "Form endpoints registered for this project.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["slug"],
        "properties": {
          "slug": {
            "type": "string",
            "minLength": 1,
            "pattern": "^[a-z0-9][a-z0-9-]{0,62}$"
          },
          "name": { "type": "string" }
        }
      }
    },
    "domains": {
      "type": "object",
      "additionalProperties": false,
      "description": "Custom hostnames attached per environment.",
      "properties": {
        "production": { "$ref": "#/$defs/hostnameArray" },
        "staging": { "$ref": "#/$defs/hostnameArray" },
        "development": { "$ref": "#/$defs/hostnameArray" }
      }
    },
    "pinpoints": {
      "type": "object",
      "additionalProperties": false,
      "description": "Pinpoints widget toggle per environment. Defaults: staging+development on, production off.",
      "properties": {
        "production": { "type": "boolean", "default": false },
        "staging": { "type": "boolean", "default": true },
        "development": { "type": "boolean", "default": true },
        "redact": {
          "type": "array",
          "description": "CSS selectors to auto-redact in captured screenshots.",
          "items": { "type": "string", "minLength": 1 }
        },
        "storeIp": {
          "type": "boolean",
          "default": true,
          "description": "If false, visitor IPs are not retained for spam mitigation."
        }
      }
    },
    "auto": {
      "type": "object",
      "additionalProperties": false,
      "description": "Caddi Auto behavior overrides for this project.",
      "properties": {
        "timeout": {
          "type": "integer",
          "minimum": 60,
          "maximum": 1800,
          "default": 480,
          "description": "Per-request hard timeout in seconds."
        }
      }
    }
  },
  "$defs": {
    "environment": {
      "type": "object",
      "additionalProperties": false,
      "required": ["branch"],
      "properties": {
        "branch": {
          "type": "string",
          "minLength": 1,
          "description": "Git branch name that maps to this environment."
        }
      }
    },
    "hostnameArray": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "pattern": "^(?=.{1,253}$)([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)(\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$"
      }
    }
  }
}
