@echo off
setlocal

set "SCRIPT_DIR=%~dp0"
set "PS1=%SCRIPT_DIR%iplayerfixer.ps1"

if not exist "%PS1%" (
    echo Could not find "%PS1%"
    exit /b 1
)

set "MODE=%~1"
if /I "%MODE%"=="preview" goto preview
if /I "%MODE%"=="whatif" goto preview
if /I "%MODE%"=="copy" goto copy
if /I "%MODE%"=="move" goto move
if /I "%MODE%"=="" goto move

echo Usage:
echo   iplayerfixer
echo     Moves matching files from the current folder into Show\Series N folders.
echo   iplayerfixer preview
echo     Shows what would happen without moving anything.
echo   iplayerfixer copy
echo     Copies files instead of moving them.
echo.
echo Current folder:
echo   %CD%
goto end

:preview
powershell -NoProfile -ExecutionPolicy Bypass -File "%PS1%" -SourceDir "%CD%" -LibraryRoot "%CD%" -Move -WhatIf
goto end

:copy
powershell -NoProfile -ExecutionPolicy Bypass -File "%PS1%" -SourceDir "%CD%" -LibraryRoot "%CD%"
goto end

:move
powershell -NoProfile -ExecutionPolicy Bypass -File "%PS1%" -SourceDir "%CD%" -LibraryRoot "%CD%" -Move

:end
echo.
pause
endlocal
