#!/bin/bash

# BondaCare MySQL Upload Script for Hostinger
# This script helps you prepare and upload your database to Hostinger

echo "=========================================="
echo "BondaCare MySQL Export to Hostinger"
echo "=========================================="
echo ""

# Check if export file exists
if [ ! -f "bondacare_hostinger_full_export.sql" ]; then
    echo "❌ Error: bondacare_hostinger_full_export.sql not found!"
    echo "Please make sure the export file exists in the current directory."
    exit 1
fi

# Display file information
echo "📁 Export File Information:"
echo "   File: bondacare_hostinger_full_export.sql"
ls -lh bondacare_hostinger_full_export.sql | awk '{print "   Size: " $5}'
echo ""

# Count INSERT statements
INSERT_COUNT=$(grep -c "INSERT INTO" bondacare_hostinger_full_export.sql 2>/dev/null || echo "0")
echo "📊 Data Summary:"
echo "   INSERT statements: $INSERT_COUNT"
echo ""

# Check file integrity
echo "🔍 File Integrity Check:"
if grep -q "CREATE TABLE" bondacare_hostinger_full_export.sql; then
    echo "   ✅ Contains table structures"
else
    echo "   ❌ Missing table structures"
fi

if [ "$INSERT_COUNT" -gt "0" ]; then
    echo "   ✅ Contains data (INSERT statements)"
else
    echo "   ⚠️  No data found (schema only)"
fi

if grep -q "DROP TABLE IF EXISTS" bondacare_hostinger_full_export.sql; then
    echo "   ✅ Contains DROP statements (safe for import)"
else
    echo "   ⚠️  No DROP statements found"
fi

echo ""
echo "=========================================="
echo "Next Steps:"
echo "=========================================="
echo ""
echo "1. Upload the file to Hostinger:"
echo "   - Via File Manager: Upload bondacare_hostinger_full_export.sql"
echo "   - Via SFTP: scp bondacare_hostinger_full_export.sql user@host:/path/"
echo ""
echo "2. Import via phpMyAdmin:"
echo "   - Login to Hostinger CyberPanel"
echo "   - Go to Databases > phpMyAdmin"
echo "   - Select your database"
echo "   - Click Import tab"
echo "   - Choose bondacare_hostinger_full_export.sql"
echo "   - Click Go"
echo ""
echo "3. OR Import via Command Line:"
echo "   mysql -u username -p database_name < bondacare_hostinger_full_export.sql"
echo ""
echo "📖 For detailed instructions, see: HOSTINGER_MYSQL_DEPLOYMENT_GUIDE.md"
echo ""
echo "=========================================="
