# .NET 9 SDK (use 8.0 if your solution targets 8)
# Force amd64 so IBM i Access RPM can be installed even on Apple Silicon hosts.
FROM --platform=linux/amd64 mcr.microsoft.com/dotnet/sdk:9.0

# Java runtime is required by Sonar
RUN apt-get update && apt-get install -y --no-install-recommends \
    openjdk-17-jre-headless curl ca-certificates git unzip gnupg \
    unixodbc unixodbc-dev alien \
    && rm -rf /var/lib/apt/lists/*

# Node.js 20.x is required by SonarLint for VS Code
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get update \
    && apt-get install -y --no-install-recommends nodejs \
    && rm -rf /var/lib/apt/lists/*

# Install IBM i Access ODBC driver when the RPM is present in the repo
COPY drivers/ /tmp/drivers/
RUN set -ex; \
    if ls /tmp/drivers/ibm-iaccess-*.rpm.disabled >/dev/null 2>&1; then \
        for f in /tmp/drivers/ibm-iaccess-*.rpm.disabled; do mv "$f" "${f%.disabled}"; done; \
    fi
RUN set -ex; \
    if ls /tmp/drivers/ibm-iaccess-*.rpm >/dev/null 2>&1; then \
        for f in /tmp/drivers/ibm-iaccess-*.rpm; do alien -i --scripts "$f"; done; \
    else \
        echo ">> IBM i Access ODBC RPM not found in /tmp/drivers. ODBC connections will fail until it is added."; \
    fi

# Register ODBC driver/DSN so unixODBC knows about the IBM driver
COPY docker/odbc/odbcinst.ini /etc/odbcinst.ini
COPY docker/odbc/odbc.ini /etc/odbc.ini

# Global tools: dotnet-sonarscanner (+ coverlet for coverage)
RUN dotnet tool install --global dotnet-sonarscanner \
 && dotnet tool install --global coverlet.console
ENV PATH="${PATH}:/root/.dotnet/tools"

# Non-root user (Dev Containers convention)
RUN useradd -ms /bin/bash vscode
USER vscode
WORKDIR /workspaces
