# [Choice] Node.js version: 20, 18, 16
ARG VARIANT=20-bullseye
FROM mcr.microsoft.com/devcontainers/javascript-node:1-${VARIANT}

# Install additional OS packages
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
    && apt-get -y install --no-install-recommends \
        sqlite3 \
        ffmpeg \
        handbrake-cli \
        curl \
        wget \
        git \
        htop \
        tree \
        jq \
        unzip \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Install pnpm globally
RUN npm install -g pnpm@latest

# Set up pnpm store location
ENV PNPM_HOME="/home/node/.local/share/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

# Create workspace directory
RUN mkdir -p /workspaces/watch-finished-turbo
WORKDIR /workspaces/watch-finished-turbo

# Switch to node user
USER node

# Set up git configuration (will be overridden by user)
RUN git config --global init.defaultBranch main

# Pre-install common global packages
RUN pnpm add -g \
    turbo \
    typescript \
    @types/node \
    eslint \
    prettier \
    jest \
    playwright

# Set default shell
ENV SHELL=/bin/bash

# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
    CMD node --version || exit 1