# Build stage
FROM mcr.microsoft.com/dotnet/sdk:10.0@sha256:f061e5a7532b36fa1d1b684857fe1f504ba92115b9934f154643266613c44c62 AS build

WORKDIR /src

# Copy project files
COPY ["VotingSystem.Api/VotingSystem.Api.csproj", "VotingSystem.Api/"]

# Restore dependencies
RUN dotnet restore "VotingSystem.Api/VotingSystem.Api.csproj"

# Copy source code
COPY . .

# Install EF Core tools
RUN dotnet tool install --global dotnet-ef

# Build the application
RUN dotnet build "VotingSystem.Api/VotingSystem.Api.csproj" -c Release -o /app/build

# Publish stage
FROM build AS publish

RUN dotnet publish "VotingSystem.Api/VotingSystem.Api.csproj" -c Release -o /app/publish

# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:10.0@sha256:ccdca44cd4f256d50187f920dc8ccc2a9ea7a8a4597ac1d51e08fddb2e3b3205 AS final

WORKDIR /app

# Expose port
EXPOSE 8080

# Copy published application from publish stage
COPY --from=publish /app/publish .

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

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