FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
WORKDIR /app
EXPOSE 8080

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

# Copy main projects
COPY ["FrontOffice.BFF.WebApi/FrontOffice.BFF.WebApi.csproj", "FrontOffice.BFF.WebApi/"]
COPY ["FrontOffice.BFF.WebApi/NuGet.config", "FrontOffice.BFF.WebApi/"]
COPY ["FrontOffice.BFF.Application/FrontOffice.BFF.Application.csproj", "FrontOffice.BFF.Application/"]
COPY ["FrontOffice.BFF.Infrastructure/FrontOffice.BFF.Infrastructure.csproj", "FrontOffice.BFF.Infrastructure/"]
COPY ["FrontOffice.BFF.Domain/FrontOffice.BFF.Domain.csproj", "FrontOffice.BFF.Domain/"]

# Copy all Protobuf projects
COPY ["Protobufs/FrontOffice.BFF.Category.Protobuf/FrontOffice.BFF.Category.Protobuf.csproj", "Protobufs/FrontOffice.BFF.Category.Protobuf/"]
COPY ["Protobufs/FrontOffice.BFF.ClubMembership.Protobuf/FrontOffice.BFF.ClubMembership.Protobuf.csproj", "Protobufs/FrontOffice.BFF.ClubMembership.Protobuf/"]
COPY ["Protobufs/FrontOffice.BFF.Commission.Protobuf/FrontOffice.BFF.Commission.Protobuf.csproj", "Protobufs/FrontOffice.BFF.Commission.Protobuf/"]
COPY ["Protobufs/FrontOffice.BFF.DiscountShop.Protobuf/FrontOffice.BFF.DiscountShop.Protobuf.csproj", "Protobufs/FrontOffice.BFF.DiscountShop.Protobuf/"]
COPY ["Protobufs/FrontOffice.BFF.NetworkMembership.Protobuf/FrontOffice.BFF.NetworkMembership.Protobuf.csproj", "Protobufs/FrontOffice.BFF.NetworkMembership.Protobuf/"]
COPY ["Protobufs/FrontOffice.BFF.Package.Protobuf/FrontOffice.BFF.Package.Protobuf.csproj", "Protobufs/FrontOffice.BFF.Package.Protobuf/"]
COPY ["Protobufs/FrontOffice.BFF.Products.Protobuf/FrontOffice.BFF.Products.Protobuf.csproj", "Protobufs/FrontOffice.BFF.Products.Protobuf/"]
COPY ["Protobufs/FrontOffice.BFF.ShopingCart.Protobuf/FrontOffice.BFF.ShopingCart.Protobuf.csproj", "Protobufs/FrontOffice.BFF.ShopingCart.Protobuf/"]
COPY ["Protobufs/FrontOffice.BFF.Transaction.Protobuf/FrontOffice.BFF.Transaction.Protobuf.csproj", "Protobufs/FrontOffice.BFF.Transaction.Protobuf/"]
COPY ["Protobufs/FrontOffice.BFF.User.Protobuf/FrontOffice.BFF.User.Protobuf.csproj", "Protobufs/FrontOffice.BFF.User.Protobuf/"]
COPY ["Protobufs/FrontOffice.BFF.UserAddress.Protobuf/FrontOffice.BFF.UserAddress.Protobuf.csproj", "Protobufs/FrontOffice.BFF.UserAddress.Protobuf/"]
COPY ["Protobufs/FrontOffice.BFF.UserOrder.Protobuf/FrontOffice.BFF.UserOrder.Protobuf.csproj", "Protobufs/FrontOffice.BFF.UserOrder.Protobuf/"]
COPY ["Protobufs/FrontOffice.BFF.UserWallet.Protobuf/FrontOffice.BFF.UserWallet.Protobuf.csproj", "Protobufs/FrontOffice.BFF.UserWallet.Protobuf/"]

RUN dotnet restore "FrontOffice.BFF.WebApi/FrontOffice.BFF.WebApi.csproj" --configfile "FrontOffice.BFF.WebApi/NuGet.config"

COPY . .
WORKDIR "/src/FrontOffice.BFF.WebApi"
RUN dotnet build "FrontOffice.BFF.WebApi.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "FrontOffice.BFF.WebApi.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .

ENV ASPNETCORE_URLS=http://+:8080
ENTRYPOINT ["dotnet", "FrontOffice.BFF.WebApi.dll"]
