FROM node:20-alpine AS builder
WORKDIR /app
COPY package.json yarn.lock .yarnrc.yml ./
COPY .yarn ./.yarn
RUN corepack enable && yarn install

# Generate Prisma Client
COPY prisma ./prisma/
RUN yarn prisma generate

# Build TypeScript
COPY tsconfig.json ./
COPY src ./src/
RUN yarn tsc

FROM node:20-alpine AS runner
WORKDIR /app
COPY package.json yarn.lock .yarnrc.yml ./
COPY .yarn ./.yarn
RUN corepack enable && yarn install

COPY --from=builder /app/node_modules/@prisma/client ./node_modules/@prisma/client
COPY --from=builder /app/dist ./dist

CMD ["yarn", "node", "dist/index.js"]
