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

# Copy solution
COPY src/BackOffice.BFF.sln ./

# Copy all project files
COPY src/BackOffice.BFF.WebApi/*.csproj ./BackOffice.BFF.WebApi/
COPY src/BackOffice.BFF.Application/*.csproj ./BackOffice.BFF.Application/
COPY src/BackOffice.BFF.Infrastructure/*.csproj ./BackOffice.BFF.Infrastructure/
COPY src/BackOffice.BFF.Domain/*.csproj ./BackOffice.BFF.Domain/
COPY src/Protobufs/BackOffice.BFF.Products.Protobuf/*.csproj ./Protobufs/BackOffice.BFF.Products.Protobuf/
COPY src/Protobufs/BackOffice.BFF.PublicMessage.Protobuf/*.csproj ./Protobufs/BackOffice.BFF.PublicMessage.Protobuf/
COPY src/Protobufs/BackOffice.BFF.ClubMembership.Protobuf/*.csproj ./Protobufs/BackOffice.BFF.ClubMembership.Protobuf/
COPY src/Protobufs/BackOffice.BFF.Commission.Protobuf/*.csproj ./Protobufs/BackOffice.BFF.Commission.Protobuf/
COPY src/Protobufs/BackOffice.BFF.Package.Protobuf/*.csproj ./Protobufs/BackOffice.BFF.Package.Protobuf/
COPY src/Protobufs/BackOffice.BFF.UserAddress.Protobuf/*.csproj ./Protobufs/BackOffice.BFF.UserAddress.Protobuf/
COPY src/Protobufs/BackOffice.BFF.VipPlan.Protobuf/*.csproj ./Protobufs/BackOffice.BFF.VipPlan.Protobuf/
COPY src/Protobufs/BackOffice.BFF.StadiumAddress.Protobuf/*.csproj ./Protobufs/BackOffice.BFF.StadiumAddress.Protobuf/

# Restore dependencies
RUN dotnet restore "BackOffice.BFF.WebApi/BackOffice.BFF.WebApi.csproj"

# Copy source code
COPY src/ ./

# Build and publish
RUN dotnet publish "BackOffice.BFF.WebApi/BackOffice.BFF.WebApi.csproj" -c Release -o /app/publish --no-restore

FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
WORKDIR /app
COPY --from=build /app/publish .

ENV ASPNETCORE_URLS=http://+:8080
EXPOSE 8080

ENTRYPOINT ["dotnet", "BackOffice.BFF.WebApi.dll"]
