# Verwende das TypeScript-Node-Image als Basis
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-20 AS base
ARG DART_VERSION=3.6.0-1
ARG GO_VERSION=1.21.0

# Definiere den Benutzername als Argument (Standard: vscode)
ARG USERNAME=vscode
ARG USER_UID=1001
ARG USER_GID=1001

# Installiere Dart
RUN apt-get update && apt-get install -y wget gnupg \
  && wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /usr/share/keyrings/dart.gpg \
  && echo "deb [signed-by=/usr/share/keyrings/dart.gpg] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main" > /etc/apt/sources.list.d/dart_stable.list \
  && apt-get update && apt-get install -y dart=${DART_VERSION}

# Erstelle den Benutzer dynamisch, falls er nicht existiert
RUN if ! getent group $USER_GID > /dev/null; then groupadd --gid $USER_GID $USERNAME; fi \
  && if ! id -u $USERNAME > /dev/null 2>&1; then useradd --uid $USER_UID --gid $USER_GID -m $USERNAME; fi \
  && echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/$USERNAME \
  && chmod 0440 /etc/sudoers.d/$USERNAME


# Installiere Go
RUN wget https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz \
  && tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz \
  && rm go${GO_VERSION}.linux-amd64.tar.gz \
  && echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile

# Installiere Fish-Shell und Oh My Fish (OMF)
RUN apt-get update && apt-get install -y fish git curl \
  && curl -L https://get.oh-my.fish | fish

# Setze Fish als Standardshell
RUN chsh -s /usr/bin/fish ${USERNAME} || echo "User ${USERNAME} not found; skipping chsh"


# Installiere das bobthefish Theme und Plugins
RUN fish -c "omf install bobthefish" \
  && fish -c "omf install bang-bang pj z"

# Optional: Konfiguration von bobthefish
RUN echo "set -g theme_nerd_fonts yes" >> ~/.config/fish/config.fish \
  && echo "set -g theme_display_git_untracked_files no" >> ~/.config/fish/config.fish


# Installiere Deno
ENV DENO_INSTALL=/deno
RUN mkdir -p /deno \
  && curl -fsSL https://deno.land/x/install/install.sh | sh \
  && chown -R vscode /deno

ENV PATH=${DENO_INSTALL}/bin:/usr/local/go/bin:${PATH} \
  DENO_DIR=${DENO_INSTALL}/.cache/deno

RUN groupadd -r docker && usermod -aG docker $USERNAME
# Definiere den Arbeitsbereich
WORKDIR /workspace

# Zusätzliche Pakete installieren
RUN apt-get update && apt-get install -y protobuf-compiler

# Ports für React und Dart Services
EXPOSE 3000 8080 4000
