FROM 194.5.195.53:32082/dotnet/sdk:9.0 AS build
WORKDIR /src

# Copy NuGet config and project file
COPY ["BackOffice/NuGet.config", "NuGet.config"]
COPY ["BackOffice/BackOffice.csproj", "BackOffice/"]

# Restore dependencies
RUN dotnet restore "BackOffice/BackOffice.csproj" --configfile NuGet.config

# Copy all source code
COPY . .

# Build and publish
WORKDIR "/src/BackOffice"
RUN dotnet publish "BackOffice.csproj" -c Release -o /app/publish

# Runtime stage - nginx for Blazor WebAssembly
FROM 194.5.195.53:32082/nginx:alpine AS final
WORKDIR /usr/share/nginx/html

# Remove default nginx files
RUN rm -rf /usr/share/nginx/html/*

# Copy published wwwroot (Blazor WASM output)
COPY --from=build /app/publish/wwwroot .

# Copy entrypoint script that sets blazor-environment header
COPY ["BackOffice/docker-entrypoint.sh", "/docker-entrypoint.sh"]
RUN chmod +x /docker-entrypoint.sh

# Default Blazor environment (override via K8s env var BLAZOR_ENVIRONMENT)
ENV BLAZOR_ENVIRONMENT=Staging
# Default gateway URL for gRPC calls (injected into appsettings at startup)
ENV GW_URL=https://cms.se.kbs1.ir

EXPOSE 80
CMD ["/docker-entrypoint.sh"]
