FROM node:20-bookworm-slim AS base

# Prisma needs OpenSSL available during install/generate/runtime.
RUN apt-get update -y && apt-get install -y openssl && rm -rf /var/lib/apt/lists/*

# Install pnpm
RUN npm install -g pnpm@9.14.2

WORKDIR /app

# Copy workspace manifests
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml* ./
COPY tooling/ ./tooling/
COPY packages/shared/package.json ./packages/shared/
COPY packages/db/package.json ./packages/db/
COPY packages/engine/package.json ./packages/engine/
COPY packages/staffing/package.json ./packages/staffing/
COPY packages/api/package.json ./packages/api/
COPY packages/ui/package.json ./packages/ui/
COPY apps/web/package.json ./apps/web/

# Install dependencies
RUN pnpm install --frozen-lockfile

# Copy all sources
COPY . .

# Generate Prisma client
RUN pnpm --filter @capakraken/db db:generate

EXPOSE 3100

CMD ["sh", "./tooling/docker/app-dev-start.sh"]
