@echo off
REM One-time setup: installs the bot and puts a "TCG Bot" icon on your Desktop.
setlocal
cd /d "%~dp0"
title TCG Bot - Setup

REM Guard: if this is running from inside the downloaded zip (a temp folder),
REM npm install + the shortcut will break. Tell them to Extract first.
echo %~dp0 | find /i "\Temp\" >nul
if not errorlevel 1 (
  echo(
  echo   It looks like you're running this from INSIDE the zip.
  echo(
  echo   Please extract it first:
  echo     1. Right-click the downloaded "tcg-bot.zip"
  echo     2. Choose "Extract All..."  then  "Extract"
  echo     3. Open the new folder and double-click SETUP again
  echo(
  pause
  exit /b 1
)

where node >nul 2>&1
if errorlevel 1 (
  echo(
  echo   Node.js isn't installed yet -- it's free and required.
  echo   Opening the download page now. Install the big green "LTS"
  echo   button, then double-click SETUP again.
  echo(
  start "" https://nodejs.org
  pause
  exit /b 1
)

echo Installing the bot... this takes a few minutes the first time.
echo (Leave this window open until it says All set.)
echo(
call npm install
if errorlevel 1 (
  echo(
  echo   Install had a problem. Take a screenshot of this window and send it over.
  pause
  exit /b 1
)

echo(
echo Creating your Desktop shortcut...
> "%TEMP%\mk_tcg_shortcut.ps1" echo $bat = '%~dp0START-BOT.bat'
>> "%TEMP%\mk_tcg_shortcut.ps1" echo $ws = New-Object -ComObject WScript.Shell
>> "%TEMP%\mk_tcg_shortcut.ps1" echo $lnk = Join-Path ([Environment]::GetFolderPath('Desktop')) 'TCG Bot.lnk'
>> "%TEMP%\mk_tcg_shortcut.ps1" echo $s = $ws.CreateShortcut($lnk)
>> "%TEMP%\mk_tcg_shortcut.ps1" echo $s.TargetPath = "$env:ComSpec"
>> "%TEMP%\mk_tcg_shortcut.ps1" echo $s.Arguments = '/c "' + $bat + '"'
>> "%TEMP%\mk_tcg_shortcut.ps1" echo $s.WorkingDirectory = '%~dp0'
>> "%TEMP%\mk_tcg_shortcut.ps1" echo $s.IconLocation = '%SystemRoot%\System32\shell32.dll,137'
>> "%TEMP%\mk_tcg_shortcut.ps1" echo $s.Description = 'Start the TCG bot'
>> "%TEMP%\mk_tcg_shortcut.ps1" echo $s.Save()
powershell -NoProfile -ExecutionPolicy Bypass -File "%TEMP%\mk_tcg_shortcut.ps1"
del "%TEMP%\mk_tcg_shortcut.ps1" >nul 2>&1

echo(
echo ============================================================
echo   All set!  A "TCG Bot" icon is now on your Desktop.
echo   Double-click it whenever you want to start the bot.
echo   (To pin it: right-click it -^> Show more options -^> Pin to taskbar.)
echo ============================================================
pause
