# Use the official ASP.NET Core runtime image
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
WORKDIR /app
EXPOSE 8080

# Use the SDK image for building
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src

# Copy project files
COPY ["LittleShop/LittleShop.csproj", "LittleShop/"]
COPY ["LittleShop.Client/LittleShop.Client.csproj", "LittleShop.Client/"]
RUN dotnet restore "LittleShop/LittleShop.csproj"

# Copy all source code
COPY . .
WORKDIR "/src/LittleShop"

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

# Publish the application
FROM build AS publish
RUN dotnet publish "LittleShop.csproj" -c Release -o /app/publish

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

# Create directories for uploads and data
RUN mkdir -p /app/wwwroot/uploads/products
RUN mkdir -p /app/data
RUN mkdir -p /app/logs

# Set permissions
RUN chmod -R 755 /app/wwwroot/uploads
RUN chmod -R 755 /app/data
RUN chmod -R 755 /app/logs

ENTRYPOINT ["dotnet", "LittleShop.dll"]