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

# Copy project file
COPY src/BackOffice/BackOffice.csproj ./BackOffice/
COPY src/BackOffice/NuGet.config ./BackOffice/

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

# Copy source code
COPY src/BackOffice/ ./BackOffice/

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

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

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

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

EXPOSE 80
