#!/bin/bash

# =============================================================================
# IDS - Quick Push to GitLab
# =============================================================================
# Script semplificato per deployment rapido
# =============================================================================

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

echo -e "${BLUE}"
echo "╔═══════════════════════════════════════════════╗"
echo "║   IDS - GitLab Deployment         ║"
echo "╔═══════════════════════════════════════════════╝"
echo -e "${NC}"

# Mostra uso
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
    echo "Uso:"
    echo ""
    echo "  ./push-gitlab.sh          → Patch version (1.0.0 → 1.0.1)"
    echo "  ./push-gitlab.sh minor    → Minor version (1.0.5 → 1.1.0)"
    echo "  ./push-gitlab.sh major    → Major version (1.1.5 → 2.0.0)"
    echo ""
    echo "Esempi:"
    echo ""
    echo "  ./push-gitlab.sh          # Fix bug, piccole modifiche"
    echo "  ./push-gitlab.sh minor    # Nuove funzionalità"
    echo "  ./push-gitlab.sh major    # Breaking changes"
    echo ""
    exit 0
fi

# Determina tipo incremento
INCREMENT_TYPE=${1:-patch}

case $INCREMENT_TYPE in
    patch)
        echo -e "${GREEN}📦 Deploy PATCH${NC} - Bug fix, piccole modifiche"
        ;;
    minor)
        echo -e "${YELLOW}🆕 Deploy MINOR${NC} - Nuove funzionalità"
        ;;
    major)
        echo -e "${BLUE}🚀 Deploy MAJOR${NC} - Breaking changes"
        ;;
    *)
        echo -e "❌ Tipo non valido: $INCREMENT_TYPE"
        echo "Usa: patch, minor, o major"
        exit 1
        ;;
esac

echo ""

# Verifica git.env
if [ ! -f "git.env" ]; then
    echo "⚠️  git.env non trovato!"
    echo ""
    echo "Crea il file git.env con queste informazioni:"
    echo ""
    echo "GITLAB_USER=tuo-username"
    echo "GITLAB_TOKEN=tuo-token-personale"
    echo "GITLAB_REPO=https://gitlab.com/tuo-username/vigilanzaturni.git"
    echo "GITLAB_BRANCH=main"
    echo ""
    echo "Ottieni il token su: https://gitlab.com/-/profile/personal_access_tokens"
    echo "Permessi richiesti: api, read_repository, write_repository"
    echo ""
    exit 1
fi

# Esegui deployment
./deploy-to-gitlab.sh "$INCREMENT_TYPE"

exit $?
