#!/usr/bin/env bash
# Cria venv em ~/Library/Application Support/VideoTask/venv com deps do motor.
set -euo pipefail
SUPPORT="${HOME}/Library/Application Support/VideoTask"
PIPELINE="$(cd "$(dirname "$0")/Pipeline" && pwd)"
REQ="${PIPELINE}/requirements.txt"
mkdir -p "${SUPPORT}"
PYTHON="${VIDEOTASK_PYTHON:-}"
if [[ -z "${PYTHON}" ]]; then
  for c in /opt/homebrew/bin/python3 /usr/local/bin/python3 /usr/bin/python3; do
    if [[ -x "$c" ]]; then PYTHON="$c"; break; fi
  done
fi
if [[ -z "${PYTHON}" ]]; then
  echo "Python 3 não encontrado. Instale via Homebrew: brew install python"
  exit 1
fi
echo "Usando ${PYTHON}"
"${PYTHON}" -m venv "${SUPPORT}/venv"
# shellcheck disable=SC1091
source "${SUPPORT}/venv/bin/activate"
pip install --upgrade pip
if [[ -f "${REQ}" ]]; then
  pip install -r "${REQ}"
else
  echo "Aviso: requirements.txt não encontrado em Pipeline/"
fi
echo "OK — venv em ${SUPPORT}/venv"
echo "Rode o VideoTask.app (Finder ou open -a VideoTask)"
