# ── Build Stage ──────────────────────────────────────────────────────────────
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src

# Copy project files for restoring dependencies
COPY timetracker.slnx ./
COPY timetracker.Server/timetracker.Server.csproj timetracker.Server/
COPY timetracker.Client/timetracker.Client.csproj timetracker.Client/
COPY timetracker.Shared/timetracker.Shared.csproj timetracker.Shared/

# Restore dependencies
RUN dotnet restore timetracker.slnx

# Copy the rest of the source code
COPY timetracker.Server/ timetracker.Server/
COPY timetracker.Client/ timetracker.Client/
COPY timetracker.Shared/ timetracker.Shared/

# Publish
WORKDIR /src/timetracker.Server
RUN dotnet publish -c Release -o /app/publish

# ── Runtime Stage ─────────────────────────────────────────────────────────────
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
WORKDIR /app
COPY --from=build /app/publish .

# Directory for SQLite database
RUN mkdir -p /data
RUN mkdir -p /app/logs

ENV ASPNETCORE_HTTP_PORTS=8080
ENV ASPNETCORE_ENVIRONMENT=Production
ENV ASPNETCORE_FORWARDEDHEADERS_ENABLED=true
ENV TIMETRACKER_DB_PATH=/data/timetracker.db
ENV TIMETRACKER_LOG_DIR=/app/logs
ENV EnableHttpsRedirect=false

EXPOSE 8080

VOLUME ["/data"]
VOLUME ["/app/logs"]

ENTRYPOINT ["dotnet", "timetracker.Server.dll"]