# Use the official Microsoft ASP.NET Core runtime as the base image.
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

# Use the official Microsoft .NET SDK image to build the code.
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["Managing.Api/Managing.Api.csproj", "Managing.Api/"]
COPY ["Managing.Bootstrap/Managing.Bootstrap.csproj", "Managing.Bootstrap/"]
COPY ["Managing.Infrastructure.Storage/Managing.Infrastructure.Storage.csproj", "Managing.Infrastructure.Storage/"]
COPY ["Managing.Application/Managing.Application.csproj", "Managing.Application/"]
COPY ["Managing.Common/Managing.Common.csproj", "Managing.Common/"]
COPY ["Managing.Core/Managing.Core.csproj", "Managing.Core/"]
COPY ["Managing.Application.Abstractions/Managing.Application.Abstractions.csproj", "Managing.Application.Abstractions/"]
COPY ["Managing.Domain/Managing.Domain.csproj", "Managing.Domain/"]
COPY ["Managing.Infrastructure.Messengers/Managing.Infrastructure.Messengers.csproj", "Managing.Infrastructure.Messengers/"]
COPY ["Managing.Infrastructure.Exchanges/Managing.Infrastructure.Exchanges.csproj", "Managing.Infrastructure.Exchanges/"]
COPY ["Managing.Infrastructure.Database/Managing.Infrastructure.Databases.csproj", "Managing.Infrastructure.Database/"]

# Restore dependencies for all projects
RUN dotnet restore "Managing.Api/Managing.Api.csproj"

# Copy everything else and build
COPY . .
WORKDIR "/src/Managing.Api"
RUN dotnet build "Managing.Api.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Managing.Api.csproj" -c Release -o /app/publish

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

ENTRYPOINT ["dotnet", "Managing.Api.dll"]

#RUN ls -la /buildapp

#WORKDIR "/buildapp/Managing.Api"

#RUN ls -la /buildapp

#RUN dotnet build "Managing.Api.csproj" -c Release -o /app/build

# FROM build AS publish
# RUN dotnet publish "Managing.Api.csproj" -c Release -o /app/publish

# FROM base AS final
# WORKDIR /app
# COPY --from=publish /app/publish .
# #COPY Managing.Api/managing_cert.pfx .
# # Managing.Api/appsettings.Lowpro.json .
# ENTRYPOINT ["dotnet", "Managing.Api.dll"]
