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

# Install Aspire CLI if you need it
RUN dotnet workload install aspire

# Copy everything
COPY . .

# Build GB5Shared first - GB5Framework projects reference its output DLL
# directly via HintPath (bin/Debug/net10.0/GB5Shared.dll), not a project
# reference, so it must exist before GB5Framework.sln can compile.
RUN dotnet restore GB5Shared/GB5Shared.sln
RUN dotnet build GB5Shared/GB5Shared.sln -c Debug

# Restore dependencies
RUN dotnet restore GB5Framework/GB5Framework.sln

# Build solution
RUN dotnet build GB5Framework/GB5Framework.sln -c Release --no-restore

# Publish only the API project
RUN dotnet publish GB5Framework/FrameworkSL/FrameworkSL.csproj -c Release -o /out/FrameworkAPI --no-build

# Stage 2: Runtime
FROM mcr.microsoft.com/dotnet/aspnet:10.0
WORKDIR /app

# Copy published output
COPY --from=build /out/FrameworkAPI ./

# Expose HTTP port
EXPOSE 5001

# Set environment variables
ENV ASPNETCORE_URLS="http://+:5001"
ENV ASPNETCORE_ENVIRONMENT="Production"

# (Optional) Set OpenTelemetry endpoint if you have a collector
# ENV OTEL_EXPORTER_OTLP_ENDPOINT="http://host.docker.internal:4317"

RUN useradd --no-create-home --shell /usr/sbin/nologin appuser
USER appuser

# Run the application
ENTRYPOINT ["dotnet", "FrameworkSL.dll"]
