# Script to push code to GitHub
cd E:\opennotion

Write-Host "========================================" -ForegroundColor Cyan
Write-Host "  Pushing OpenNotion to GitHub" -ForegroundColor Cyan  
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""

# Check git status
Write-Host "[1/5] Checking git status..." -ForegroundColor Yellow
git status
Write-Host ""

# Add all files
Write-Host "[2/5] Adding all files..." -ForegroundColor Yellow
git add .
Write-Host "Files added!" -ForegroundColor Green
Write-Host ""

# Commit changes
Write-Host "[3/5] Committing changes..." -ForegroundColor Yellow
$hasChanges = git diff --cached --quiet
if ($LASTEXITCODE -ne 0) {
    git commit -m "Update: OpenNotion project - $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
    Write-Host "Changes committed!" -ForegroundColor Green
} else {
    Write-Host "No changes to commit" -ForegroundColor Yellow
}
Write-Host ""

# Check remote
Write-Host "[4/5] Checking remote configuration..." -ForegroundColor Yellow
git remote -v
Write-Host ""

# Push to GitHub
Write-Host "[5/5] Pushing to GitHub..." -ForegroundColor Yellow
Write-Host "Repository: https://github.com/Hoanganhvu123/cuccu_note.git" -ForegroundColor Cyan
Write-Host ""
Write-Host "If this fails, you may need to:" -ForegroundColor Yellow
Write-Host "  1. Authenticate with GitHub (use Personal Access Token)" -ForegroundColor Yellow
Write-Host "  2. Or use: git push -u origin main" -ForegroundColor Yellow
Write-Host ""

git push -u origin main

if ($LASTEXITCODE -eq 0) {
    Write-Host ""
    Write-Host "========================================" -ForegroundColor Green
    Write-Host "  SUCCESS! Code pushed to GitHub!" -ForegroundColor Green
    Write-Host "  https://github.com/Hoanganhvu123/cuccu_note" -ForegroundColor Cyan
    Write-Host "========================================" -ForegroundColor Green
} else {
    Write-Host ""
    Write-Host "========================================" -ForegroundColor Red
    Write-Host "  Push failed. Error code: $LASTEXITCODE" -ForegroundColor Red
    Write-Host "========================================" -ForegroundColor Red
    Write-Host ""
    Write-Host "Common issues:" -ForegroundColor Yellow
    Write-Host "  - Authentication required (use GitHub Personal Access Token)" -ForegroundColor Yellow
    Write-Host "  - Repository doesn't exist or you don't have access" -ForegroundColor Yellow
    Write-Host "  - Network connection issue" -ForegroundColor Yellow
    Write-Host ""
    Write-Host "To fix authentication:" -ForegroundColor Cyan
    Write-Host "  git config --global credential.helper manager" -ForegroundColor White
    Write-Host "  Then try pushing again" -ForegroundColor White
}

