{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Fasecmo Deployment Configuration",
  "description": "Controls the automated deployment engine behavior. All fields are optional — sensible defaults are used when omitted.",
  "type": "object",
  "properties": {
    "version": {
      "type": "string",
      "description": "Schema version for future migrations",
      "default": "1.0.0"
    },
    "node": {
      "type": "object",
      "description": "Node.js runtime requirements",
      "properties": {
        "requiredVersion": {
          "type": "string",
          "description": "Minimum Node.js version (semver range)",
          "default": ">=20.0.0"
        },
        "preferNvm": {
          "type": "boolean",
          "description": "Use nvm if available on the host",
          "default": true
        }
      }
    },
    "database": {
      "type": "object",
      "description": "Database provisioning and migration controls",
      "properties": {
        "autoProvision": {
          "type": "boolean",
          "description": "Attempt to create database/user if missing (requires adapter support)",
          "default": true
        },
        "migrationStrategy": {
          "type": "string",
          "enum": ["migrate", "push", "seed-only"],
          "description": "How to apply schema changes",
          "default": "migrate"
        },
        "allowDataLossPush": {
          "type": "boolean",
          "description": "Allow prisma db push with --accept-data-loss=false as fallback",
          "default": false
        }
      }
    },
    "prisma": {
      "type": "object",
      "description": "Prisma client and migration settings",
      "properties": {
        "generateBeforeMigrate": {
          "type": "boolean",
          "description": "Run prisma generate before migrations",
          "default": true
        },
        "skipGenerateIfFresh": {
          "type": "boolean",
          "description": "Skip generate if client is newer than schema",
          "default": true
        }
      }
    },
    "build": {
      "type": "object",
      "description": "Build pipeline controls",
      "properties": {
        "backendCommand": {
          "type": "string",
          "description": "Override backend build command",
          "default": "npm run build"
        },
        "frontendCommand": {
          "type": "string",
          "description": "Override frontend build command",
          "default": "npm run build"
        },
        "skipFrontendBuild": {
          "type": "boolean",
          "description": "Skip frontend build (useful for API-only deploys)",
          "default": false
        }
      }
    },
    "services": {
      "type": "object",
      "description": "External service configuration",
      "properties": {
        "redis": {
          "type": "object",
          "description": "Redis configuration",
          "properties": {
            "required": {
              "type": "boolean",
              "description": "Fail deployment if Redis is unreachable",
              "default": false
            },
            "connectTimeoutMs": {
              "type": "integer",
              "description": "Timeout for Redis connectivity probe",
              "default": 5000
            }
          }
        },
        "email": {
          "type": "object",
          "description": "Email (SMTP) configuration",
          "properties": {
            "probeTimeoutMs": {
              "type": "integer",
              "description": "Timeout for SMTP connectivity probe",
              "default": 3000
            }
          }
        },
        "storage": {
          "type": "object",
          "description": "File storage configuration",
          "properties": {
            "ensureUploadsDir": {
              "type": "boolean",
              "description": "Create writable uploads/ directory",
              "default": true
            }
          }
        }
      }
    },
    "health": {
      "type": "object",
      "description": "Health check configuration",
      "properties": {
        "probeTimeoutMs": {
          "type": "integer",
          "description": "Max time to wait for API health endpoint",
          "default": 90000
        },
        "checkWebSocket": {
          "type": "boolean",
          "description": "Probe WebSocket port after startup",
          "default": true
        },
        "checkAuth": {
          "type": "boolean",
          "description": "Probe authentication endpoint after startup",
          "default": true
        }
      }
    },
    "security": {
      "type": "object",
      "description": "Security and safety controls",
      "properties": {
        "productionSafety": {
          "type": "boolean",
          "description": "Enable extra safety checks in production",
          "default": true
        },
        "backupEnvBeforeWrite": {
          "type": "boolean",
          "description": "Create .env.backup before modifying .env",
          "default": true
        },
        "maxBackups": {
          "type": "integer",
          "description": "Maximum number of .env backups to retain",
          "default": 5
        }
      }
    },
    "cors": {
      "type": "object",
      "description": "CORS configuration defaults",
      "properties": {
        "allowOrigins": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Allowed CORS origins (auto-detected when empty)"
        },
        "allowCredentials": {
          "type": "boolean",
          "default": true
        }
      }
    }
  }
}
