# --- Etapa 1: Build ---
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src

# Copia solo los archivos de proyecto primero para cachear dependencias
COPY GestionIntegralWeb.sln .
COPY Backend/GestionIntegral.Api/GestionIntegral.Api.csproj Backend/GestionIntegral.Api/

# Restaura dependencias
RUN dotnet restore "GestionIntegralWeb.sln"

# Copia el resto del código
COPY . .

# Construye el proyecto
WORKDIR "/src/Backend/GestionIntegral.Api"
RUN dotnet build "GestionIntegral.Api.csproj" -c Release -o /app/build

# --- Etapa 2: Publish ---
FROM build AS publish
RUN dotnet publish "GestionIntegral.Api.csproj" -c Release -o /app/publish /p:UseAppHost=false

# --- Etapa 3: Final ---
FROM mcr.microsoft.com/dotnet/aspnet:9.0
WORKDIR /app
COPY --from=publish /app/publish .

EXPOSE 8080
ENTRYPOINT ["dotnet", "GestionIntegral.Api.dll"]