# Particle OS - Debian Trixie with KDE Plasma Desktop
# Phase 5.1: Real Desktop Environment Integration Testing

FROM debian:trixie

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive

# Install essential packages first
RUN apt-get update && apt-get install -y \
    # Core system packages
    systemd \
    systemd-sysv \
    dbus \
    sudo \
    # Network management
    network-manager \
    network-manager-gnome \
    # Package management
    apt-utils \
    ca-certificates \
    gnupg \
    # OSTree and bootc requirements
    ostree \
    # Kernel and boot
    linux-image-amd64 \
    linux-headers-amd64 \
    initramfs-tools \
    # Bootloader
    grub-efi-amd64 \
    grub-efi-amd64-bin \
    efibootmgr \
    # Filesystem utilities
    util-linux \
    parted \
    e2fsprogs \
    dosfstools \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Install KDE Plasma Desktop Environment
RUN apt-get update && apt-get install -y \
    # KDE Desktop Environment
    task-kde-desktop \
    kde-plasma-desktop \
    plasma-workspace \
    # Display Manager
    sddm \
    # Essential KDE Applications
    dolphin \
    konsole \
    kate \
    firefox-esr \
    # Audio support
    pulseaudio \
    pavucontrol \
    # Graphics support
    mesa-utils \
    # System utilities
    nano \
    vim \
    curl \
    wget \
    htop \
    less \
    # Cleanup
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Enable essential services
RUN systemctl enable systemd-networkd \
    && systemctl enable systemd-resolved \
    && systemctl enable dbus \
    && systemctl enable sddm \
    && systemctl enable NetworkManager

# Create particle-os user with desktop access
RUN useradd -m -G sudo,audio,video,plugdev particle-os \
    && echo 'particle-os:particle-os' | chpasswd \
    && echo 'particle-os ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

# Configure SDDM for auto-login (testing purposes)
RUN mkdir -p /etc/sddm.conf.d \
    && echo '[Autologin]' > /etc/sddm.conf.d/autologin.conf \
    && echo 'User=particle-os' >> /etc/sddm.conf.d/autologin.conf \
    && echo 'Session=plasma.desktop' >> /etc/sddm.conf.d/autologin.conf

# Set up OSTree configuration for bootc
RUN mkdir -p /etc/ostree \
    && echo '[core]' > /etc/ostree/ostree.conf \
    && echo 'mode=bare-user-only' >> /etc/ostree/ostree.conf

# Configure system identification
RUN echo 'PRETTY_NAME="Particle OS (Debian Trixie KDE)"' > /etc/os-release \
    && echo 'NAME="Particle OS"' >> /etc/os-release \
    && echo 'VERSION="1.0-kde"' >> /etc/os-release \
    && echo 'ID=particle-os' >> /etc/os-release \
    && echo 'ID_LIKE=debian' >> /etc/os-release \
    && echo 'VERSION_ID="1.0"' >> /etc/os-release \
    && echo 'HOME_URL="https://particle-os.org"' >> /etc/os-release \
    && echo 'SUPPORT_URL="https://particle-os.org/support"' >> /etc/os-release \
    && echo 'BUG_REPORT_URL="https://particle-os.org/bugs"' >> /etc/os-release

# Set hostname
RUN echo 'particle-os-kde' > /etc/hostname

# Configure bootc for immutable system
RUN ln -sf /var/home /home

# Set up default KDE configuration
RUN mkdir -p /etc/skel/.config/kdeglobals \
    && mkdir -p /etc/skel/.config/plasma-org.kde.plasma.desktop-appletsrc

# Ensure proper permissions
RUN chmod 755 /etc/ostree \
    && chmod 644 /etc/ostree/ostree.conf \
    && chmod 755 /etc/sddm.conf.d \
    && chmod 644 /etc/sddm.conf.d/autologin.conf

LABEL org.opencontainers.image.title="Particle OS KDE"
LABEL org.opencontainers.image.description="Debian Trixie based Particle OS with KDE Plasma"
LABEL org.opencontainers.image.vendor="Particle OS Project"
LABEL org.opencontainers.image.version="1.0-kde"
LABEL org.particle-os.type="desktop"
LABEL org.particle-os.desktop="kde-plasma"
LABEL com.debian.bootc="true"
LABEL ostree.bootable="true"
