{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://claude-flow-novice.local/schemas/config-v1.schema.json",
  "title": "CFN Configuration Schema",
  "description": "JSON Schema for Claude Flow Novice configuration files (v1.0)",
  "type": "object",
  "properties": {
    "version": {
      "type": "string",
      "description": "Configuration schema version",
      "pattern": "^\\d+\\.\\d+(\\.\\d+)?$",
      "examples": ["1.0", "1.0.0"]
    },
    "database": {
      "type": "object",
      "description": "Database configuration",
      "properties": {
        "type": {
          "type": "string",
          "description": "Database type",
          "enum": ["sqlite", "postgres", "mysql"],
          "default": "sqlite"
        },
        "host": {
          "type": "string",
          "description": "Database host (for postgres/mysql)",
          "examples": ["localhost", "db.example.com"]
        },
        "port": {
          "type": "number",
          "description": "Database port (for postgres/mysql)",
          "minimum": 1,
          "maximum": 65535,
          "examples": [5432, 3306]
        },
        "path": {
          "type": "string",
          "description": "Database file path (for sqlite)",
          "default": "./data/cfn.db",
          "examples": ["./data/cfn.db", "/var/lib/cfn/data.db"]
        },
        "name": {
          "type": "string",
          "description": "Database name (for postgres/mysql)",
          "examples": ["cfn", "claude_flow"]
        },
        "username": {
          "type": "string",
          "description": "Database username (for postgres/mysql)"
        },
        "password": {
          "type": "string",
          "description": "Database password (for postgres/mysql)"
        },
        "pool": {
          "type": "object",
          "description": "Connection pool configuration",
          "properties": {
            "min": {
              "type": "number",
              "description": "Minimum pool size",
              "minimum": 0,
              "default": 2
            },
            "max": {
              "type": "number",
              "description": "Maximum pool size",
              "minimum": 1,
              "default": 10
            }
          }
        },
        "ssl": {
          "type": "boolean",
          "description": "Enable SSL connection",
          "default": false
        }
      },
      "required": ["type"],
      "allOf": [
        {
          "if": {
            "properties": { "type": { "const": "sqlite" } }
          },
          "then": {
            "required": ["path"]
          }
        },
        {
          "if": {
            "properties": { "type": { "enum": ["postgres", "mysql"] } }
          },
          "then": {
            "required": ["host", "port", "name"]
          }
        }
      ]
    },
    "redis": {
      "type": "object",
      "description": "Redis configuration",
      "properties": {
        "enabled": {
          "type": "boolean",
          "description": "Enable Redis support",
          "default": true
        },
        "host": {
          "type": "string",
          "description": "Redis host",
          "default": "localhost"
        },
        "port": {
          "type": "number",
          "description": "Redis port",
          "minimum": 1,
          "maximum": 65535,
          "default": 6379
        },
        "password": {
          "type": "string",
          "description": "Redis password (optional)"
        },
        "db": {
          "type": "number",
          "description": "Redis database number",
          "minimum": 0,
          "maximum": 15,
          "default": 0
        },
        "ttl": {
          "type": "number",
          "description": "Default TTL in seconds",
          "minimum": 0,
          "default": 86400
        },
        "keyPrefix": {
          "type": "string",
          "description": "Key prefix for namespacing",
          "default": "cfn:"
        }
      }
    },
    "agents": {
      "type": "object",
      "description": "Agent configuration",
      "properties": {
        "maxConcurrent": {
          "type": "number",
          "description": "Maximum concurrent agents",
          "minimum": 1,
          "maximum": 1000,
          "default": 10
        },
        "timeout": {
          "type": "number",
          "description": "Agent timeout in seconds",
          "minimum": 1,
          "default": 300
        },
        "retryAttempts": {
          "type": "number",
          "description": "Number of retry attempts on failure",
          "minimum": 0,
          "maximum": 10,
          "default": 3
        },
        "retryDelay": {
          "type": "number",
          "description": "Delay between retries in milliseconds",
          "minimum": 0,
          "default": 1000
        },
        "defaultStrategy": {
          "type": "string",
          "description": "Default agent strategy",
          "enum": ["development", "production", "testing"],
          "default": "development"
        },
        "logLevel": {
          "type": "string",
          "description": "Agent log level",
          "enum": ["debug", "info", "warn", "error"],
          "default": "info"
        }
      }
    },
    "skills": {
      "type": "object",
      "description": "Skills configuration",
      "properties": {
        "directory": {
          "type": "string",
          "description": "Skills directory path",
          "default": "./.claude/skills"
        },
        "autoload": {
          "type": "boolean",
          "description": "Automatically load skills on startup",
          "default": true
        },
        "allowedTypes": {
          "type": "array",
          "description": "Allowed skill types",
          "items": {
            "type": "string"
          },
          "default": ["coordination", "deployment", "testing", "validation"]
        },
        "cache": {
          "type": "object",
          "properties": {
            "enabled": {
              "type": "boolean",
              "default": true
            },
            "ttl": {
              "type": "number",
              "description": "Cache TTL in seconds",
              "default": 3600
            }
          }
        }
      }
    },
    "logging": {
      "type": "object",
      "description": "Logging configuration",
      "properties": {
        "level": {
          "type": "string",
          "enum": ["debug", "info", "warn", "error"],
          "default": "info"
        },
        "format": {
          "type": "string",
          "enum": ["json", "text", "pretty"],
          "default": "json"
        },
        "output": {
          "type": "string",
          "enum": ["stdout", "file", "both"],
          "default": "stdout"
        },
        "file": {
          "type": "object",
          "properties": {
            "path": {
              "type": "string",
              "default": "./logs/cfn.log"
            },
            "maxSize": {
              "type": "string",
              "description": "Max file size (e.g., '10m', '100k')",
              "default": "10m"
            },
            "maxFiles": {
              "type": "number",
              "description": "Maximum number of log files",
              "default": 5
            }
          }
        }
      }
    },
    "security": {
      "type": "object",
      "description": "Security configuration",
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": true
        },
        "apiKeyRequired": {
          "type": "boolean",
          "description": "Require API key for operations",
          "default": false
        },
        "rateLimiting": {
          "type": "object",
          "properties": {
            "enabled": {
              "type": "boolean",
              "default": true
            },
            "maxRequests": {
              "type": "number",
              "description": "Max requests per window",
              "default": 100
            },
            "windowMs": {
              "type": "number",
              "description": "Time window in milliseconds",
              "default": 60000
            }
          }
        },
        "allowedOrigins": {
          "type": "array",
          "description": "Allowed CORS origins",
          "items": {
            "type": "string"
          },
          "default": ["http://localhost:3000"]
        }
      }
    },
    "monitoring": {
      "type": "object",
      "description": "Monitoring configuration",
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": true
        },
        "prometheus": {
          "type": "object",
          "properties": {
            "enabled": {
              "type": "boolean",
              "default": false
            },
            "port": {
              "type": "number",
              "default": 9090
            },
            "path": {
              "type": "string",
              "default": "/metrics"
            }
          }
        },
        "healthCheck": {
          "type": "object",
          "properties": {
            "enabled": {
              "type": "boolean",
              "default": true
            },
            "port": {
              "type": "number",
              "default": 8080
            },
            "path": {
              "type": "string",
              "default": "/health"
            }
          }
        }
      }
    },
    "features": {
      "type": "object",
      "description": "Feature flags",
      "properties": {
        "hotReload": {
          "type": "boolean",
          "description": "Enable hot reload of configuration",
          "default": false
        },
        "customRouting": {
          "type": "boolean",
          "description": "Enable custom provider routing",
          "default": false
        },
        "experimentalFeatures": {
          "type": "boolean",
          "description": "Enable experimental features",
          "default": false
        }
      }
    }
  },
  "required": ["version", "database"],
  "additionalProperties": true
}
