# ── Stage 1: Build ──────────────────────────────────────────────────────────
ARG DOTNET_SDK_IMAGE=mcr.microsoft.com/dotnet/sdk:10.0
FROM ${DOTNET_SDK_IMAGE} AS build
WORKDIR /src

# NuGet through Nexus mirror
COPY nuget.docker.config /tmp/nuget.config

# Restore (layer-cached unless .csproj changes)
COPY AsadiTools.csproj .
RUN dotnet restore --configfile /tmp/nuget.config

# Copy everything else and publish
COPY . .
RUN dotnet publish -c Release -o /app/publish --no-restore

# ── Stage 2: Runtime ─────────────────────────────────────────────────────────
ARG DOTNET_RUNTIME_IMAGE=mcr.microsoft.com/dotnet/aspnet:10.0
FROM ${DOTNET_RUNTIME_IMAGE} AS runtime
WORKDIR /app

# Create data directory for SQLite volume mount
RUN mkdir -p /app/data && chmod 777 /app/data

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

# Override connection string to use /app/data/asadi.db (volume path)
ENV ConnectionStrings__Default="Data Source=/app/data/asadi.db"
ENV ASPNETCORE_URLS="http://+:4310"
ENV ASPNETCORE_ENVIRONMENT="Production"

EXPOSE 4310

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