# Project Specification for Complete Project Generation
# This file defines all variables, modules, and generation order

project:
  name: web-service-template
  description: Complete Rust web service with REST API, models, and tests
  version: 0.1.0
  rust_edition: 2021

# Variables available to all templates
variables:
  project_name: my-web-service
  version: 0.1.0
  author: Generated by ggen
  description: A production-ready Rust web service
  port: 3000
  log_level: info
  rust_edition: 2021

  # Feature flags
  enable_auth: true
  enable_logging: true
  enable_metrics: false

  # Database configuration
  database_enabled: true
  database_url: postgresql://localhost/myapp

  # API configuration
  api_prefix: /api
  api_version: v1
  cors_enabled: true

  # Testing
  test_coverage_target: 80
  integration_tests: true

# Dependencies for Cargo.toml
dependencies:
  runtime:
    - name: actix-web
      version: 4.4
      features: []
    - name: actix-rt
      version: 2.9
      features: []
    - name: serde
      version: 1.0
      features: [derive]
    - name: serde_json
      version: 1.0
      features: []
    - name: tokio
      version: 1.35
      features: [full]
    - name: env_logger
      version: 0.11
      features: []
    - name: log
      version: 0.4
      features: []
    - name: chrono
      version: 0.4
      features: [serde]
    - name: uuid
      version: 1.6
      features: [v4, serde]
    - name: validator
      version: 0.16
      features: [derive]

  dev:
    - name: reqwest
      version: 0.11
      features: [json]
    - name: mockito
      version: 1.2
      features: []

# Modules to generate (in order)
modules:
  - name: cargo_config
    description: Package configuration
    template: cargo-toml.tmpl
    output: Cargo.toml
    required: true

  - name: main
    description: Application entry point
    template: main-rs.tmpl
    output: src/main.rs
    required: true

  - name: models_mod
    description: Models module definition
    template: models-mod.tmpl
    output: src/models/mod.rs
    required: true

  - name: user_model
    description: User data model
    template: user-model.tmpl
    output: src/models/user.rs
    required: true

  - name: product_model
    description: Product data model
    template: product-model.tmpl
    output: src/models/product.rs
    required: true

  - name: api_mod
    description: API module definition
    template: api-mod.tmpl
    output: src/api/mod.rs
    required: true

  - name: api_handlers
    description: Request handlers
    template: api-handlers.tmpl
    output: src/api/handlers.rs
    required: true

  - name: api_routes
    description: Route configuration
    template: api-routes.tmpl
    output: src/api/routes.rs
    required: true

  - name: config_mod
    description: Config module definition
    template: config-mod.tmpl
    output: src/config/mod.rs
    required: true

  - name: config_settings
    description: Application settings
    template: config-settings.tmpl
    output: src/config/settings.rs
    required: true

  - name: integration_tests
    description: Integration tests
    template: integration-test.tmpl
    output: tests/integration_test.rs
    required: false
    condition: "{{integration_tests}}"

# Generation order and dependencies
generation:
  phases:
    - name: structure
      description: Create project structure
      modules: [cargo_config]

    - name: models
      description: Generate data models
      modules: [models_mod, user_model, product_model]
      depends_on: [structure]

    - name: api
      description: Generate API layer
      modules: [api_mod, api_handlers, api_routes]
      depends_on: [models]

    - name: config
      description: Generate configuration
      modules: [config_mod, config_settings]
      depends_on: [structure]

    - name: application
      description: Generate main application
      modules: [main]
      depends_on: [models, api, config]

    - name: tests
      description: Generate tests
      modules: [integration_tests]
      depends_on: [application]

# Post-generation hooks
hooks:
  post_generate:
    - command: cargo fmt
      description: Format generated code
      working_dir: output/{{project_name}}

    - command: cargo check
      description: Verify compilation
      working_dir: output/{{project_name}}

    - command: cargo test
      description: Run tests
      working_dir: output/{{project_name}}
      allow_failure: false

# Validation rules
validation:
  required_variables:
    - project_name
    - version
    - port

  variable_types:
    port:
      type: integer
      min: 1024
      max: 65535

    version:
      type: string
      pattern: '^\d+\.\d+\.\d+$'

    project_name:
      type: string
      pattern: '^[a-z][a-z0-9-]*$'

  file_checks:
    - path: output/{{project_name}}/Cargo.toml
      must_contain: '[package]'

    - path: output/{{project_name}}/src/main.rs
      must_contain: 'fn main()'

# Documentation
documentation:
  readme_template: README.md
  api_docs: true
  generate_changelog: true
  examples:
    - basic_usage.md
    - advanced_configuration.md
