//! Quality script template

/// Generate project-specific quality script
#[allow(dead_code)] // Template for future use
pub fn quality_script(project_name: &str) -> String {
    format!(
        r#"#!/usr/bin/env bash
#
# {} Code Quality Script
#
# Runs code quality checks (format, lint, build, test) for this robot project.
#
# Usage:
#   mecha10 lint                          # Run linting (recommended)
#   mecha10 format                        # Format code
#   ./scripts/quality.sh <TOOL> [OPTIONS] # Direct script usage
#
# Tools:
#   format    Format Rust code
#   lint      Lint Rust code (clippy + format check)
#   build     Build project
#   test      Run tests
#   all       Run all checks (lint + build + test)
#
# Options:
#   --check   For format: check only, don't modify
#   --quiet   Suppress output (errors still shown)
#

set -e

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'

# Options
CHECK_ONLY=false
QUIET=false
TOOL="${{1:-all}}"

# Parse options
shift || true
while [[ $# -gt 0 ]]; do
    case $1 in
        --check)
            CHECK_ONLY=true
            shift
            ;;
        --quiet)
            QUIET=true
            shift
            ;;
        *)
            echo "Unknown option: $1"
            echo "Usage: $0 <tool> [--check] [--quiet]"
            exit 1
            ;;
    esac
done

# Logging functions
log_info() {{ [ "$QUIET" = false ] && echo -e "${{BLUE}}ℹ${{NC}} $1" || true; }}
log_success() {{ echo -e "${{GREEN}}✓${{NC}} $1"; }}
log_error() {{ echo -e "${{RED}}✗${{NC}} $1" >&2; }}

# Tool runners
run_format() {{
    log_info "Running cargo fmt..."
    if [ "$CHECK_ONLY" = true ]; then
        if cargo fmt -- --check; then
            log_success "Code is properly formatted"
        else
            log_error "Code formatting issues found"
            exit 1
        fi
    else
        cargo fmt
        log_success "Code formatted successfully"
    fi
}}

run_lint() {{
    log_info "Running cargo clippy..."
    if cargo clippy --workspace --all-targets -- -D warnings; then
        log_success "No clippy warnings"
    else
        log_error "Clippy found issues"
        exit 1
    fi

    log_info "Checking code formatting..."
    if cargo fmt -- --check; then
        log_success "Code is properly formatted"
    else
        log_error "Code formatting issues found. Run: mecha10 format"
        exit 1
    fi
}}

run_build() {{
    log_info "Building project..."
    if cargo build --workspace; then
        log_success "Build successful"
    else
        log_error "Build failed"
        exit 1
    fi
}}

run_test() {{
    log_info "Running tests..."
    if cargo test --workspace; then
        log_success "All tests passed"
    else
        log_error "Tests failed"
        exit 1
    fi
}}

run_all() {{
    log_info "Running all quality checks..."
    run_lint
    run_build
    run_test
    log_success "All quality checks passed!"
}}

# Main execution
case "$TOOL" in
    format)
        run_format
        ;;
    lint)
        run_lint
        ;;
    build)
        run_build
        ;;
    test)
        run_test
        ;;
    all)
        run_all
        ;;
    *)
        echo "Unknown tool: $TOOL"
        echo "Available tools: format, lint, build, test, all"
        exit 1
        ;;
esac
"#,
        project_name
    )
}
