{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Servercn Config",
  "description": "Flat configuration schema for Servercn projects",
  "type": "object",
  "additionalProperties": false,

  "required": [
    "$schema",
    "version",
    "rootDir",
    "packageManager",
    "runtime",
    "language",
    "framework",
    "architecture"
  ],

  "properties": {
    "$schema": {
      "type": "string",
      "description": "JSON schema reference"
    },

    "version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+$",
      "description": "Semver version"
    },

    "rootDir": {
      "type": "string",
      "default": ".",
      "description": "Project root directory"
    },

    "packageManager": {
      "type": "string",
      "enum": ["npm", "pnpm", "bun", "yarn"],
      "default": "npm"
    },

    "runtime": {
      "type": "string",
      "enum": ["node", "deno", "bun"]
    },

    "language": {
      "type": "string",
      "enum": ["typescript"],
      "default": "typescript"
    },

    "framework": {
      "type": "string"
    },

    "architecture": {
      "type": "string"
    },

    "database": {
      "oneOf": [
        { "type": "null" },
        {
          "type": "object",
          "required": ["engine", "adapter"],
          "additionalProperties": false,
          "properties": {
            "engine": {
              "type": "string",
              "enum": ["mongodb", "postgresql", "mysql"]
            },
            "adapter": {
              "type": "string"
            }
          },

          "allOf": [
            {
              "if": {
                "properties": { "engine": { "const": "mongodb" } }
              },
              "then": {
                "properties": {
                  "adapter": {
                    "enum": ["mongoose", "prisma"]
                  }
                }
              }
            },
            {
              "if": {
                "properties": { "engine": { "const": "postgresql" } }
              },
              "then": {
                "properties": {
                  "adapter": {
                    "enum": ["drizzle", "prisma"]
                  }
                }
              }
            },
            {
              "if": {
                "properties": { "engine": { "const": "mysql" } }
              },
              "then": {
                "properties": {
                  "adapter": {
                    "enum": ["drizzle", "prisma"]
                  }
                }
              }
            }
          ]
        }
      ]
    }
  },

  "allOf": [
    {
      "if": {
        "properties": { "runtime": { "const": "node" } }
      },
      "then": {
        "properties": {
          "framework": {
            "enum": ["express", "nestjs", "nextjs"]
          }
        }
      }
    },
    {
      "if": {
        "properties": { "runtime": { "const": "deno" } }
      },
      "then": {
        "properties": {
          "framework": {
            "enum": ["hono"]
          }
        }
      }
    },
    {
      "if": {
        "properties": { "runtime": { "const": "bun" } }
      },
      "then": {
        "properties": {
          "framework": {
            "enum": ["hono", "express"]
          }
        }
      }
    },

    {
      "if": {
        "properties": { "framework": { "const": "nestjs" } }
      },
      "then": {
        "properties": {
          "architecture": {
            "enum": ["modular"]
          }
        }
      }
    },
    {
      "if": {
        "properties": { "framework": { "const": "express" } }
      },
      "then": {
        "properties": {
          "architecture": {
            "enum": ["mvc", "feature"]
          }
        }
      }
    },
    {
      "if": {
        "properties": { "framework": { "const": "nextjs" } }
      },
      "then": {
        "properties": {
          "architecture": {
            "enum": ["file-api"]
          }
        }
      }
    }
  ]
}
