# ══════════════════════════════════════════
# Stage 1 — Build
# ══════════════════════════════════════════
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src

# Restore NuGet packages first (layer cache)
COPY *.csproj .
RUN dotnet restore

# Build & publish
COPY . .
RUN dotnet publish -c Release -o /app/publish --no-restore

# ══════════════════════════════════════════
# Stage 2 — Runtime
# ══════════════════════════════════════════
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
WORKDIR /app

# Dependencies for QuestPDF (PDF generation)
RUN apt-get update && apt-get install -y --no-install-recommends \
    libfontconfig1 \
    libfreetype6 \
    fontconfig \
    fonts-dejavu-core \
    && fc-cache -fv \
    && rm -rf /var/lib/apt/lists/*

# Copy published app
COPY --from=build /app/publish .

# Create required directories
RUN mkdir -p /app/exports /app/logs

EXPOSE 5000

ENTRYPOINT ["dotnet", "SupportHub.dll"]
