FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src

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

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

# Copy all source code
COPY . .

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

# Runtime stage - nginx for Blazor WebAssembly
FROM 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 .

# Configure nginx for SPA routing
RUN echo 'server { \
    listen 80; \
    server_name _; \
    location / { \
        root /usr/share/nginx/html; \
        try_files $uri $uri/ /index.html; \
    } \
}' > /etc/nginx/conf.d/default.conf

EXPOSE 80
