#!/bin/bash

# Script to easily change log levels
# Usage: ./scripts/set-log-level.sh [error|warn|info|debug|trace]

if [ $# -eq 0 ]; then
    echo "Current LOG_LEVEL: $(grep LOG_LEVEL .env | cut -d'=' -f2 | tr -d '"')"
    echo ""
    echo "Usage: $0 [error|warn|info|debug|trace]"
    echo ""
    echo "Log Levels:"
    echo "  error - Only errors (least verbose)"
    echo "  warn  - Warnings and errors"
    echo "  info  - General information (recommended)"
    echo "  debug - Detailed debugging info"
    echo "  trace - Very detailed tracing (most verbose)"
    exit 0
fi

LEVEL=$1

# Validate log level
case $LEVEL in
    error|warn|info|debug|trace)
        ;;
    *)
        echo "Invalid log level: $LEVEL"
        echo "Valid levels: error, warn, info, debug, trace"
        exit 1
        ;;
esac

# Update .env file
if [[ "$OSTYPE" == "darwin"* ]]; then
    # macOS
    sed -i '' "s/LOG_LEVEL=\".*\"/LOG_LEVEL=\"$LEVEL\"/" .env
else
    # Linux
    sed -i "s/LOG_LEVEL=\".*\"/LOG_LEVEL=\"$LEVEL\"/" .env
fi

echo "✅ Log level changed to: $LEVEL"
echo "🔄 Restart your development server to apply changes"
