FROM python:3.11-slim

# Install system deps needed by dotsync
RUN apt-get update && apt-get install -y --no-install-recommends \
    git \
    bash \
    openssh-client \
    vim-tiny \
    && rm -rf /var/lib/apt/lists/*

# Install dotsync-ai from local wheel
COPY dist/dotsync_ai-0.1.0-py3-none-any.whl /tmp/
RUN pip install --no-cache-dir /tmp/dotsync_ai-0.1.0-py3-none-any.whl && rm /tmp/*.whl

# Configure git globally (required by dotsync git backend)
RUN git config --global user.name "dotsync-tester" && \
    git config --global user.email "tester@dotsync.test" && \
    git config --global init.defaultBranch main

# Create test user home
RUN useradd -m -s /bin/bash tester
USER tester
WORKDIR /home/tester

# Pre-create some dotfiles for testing
RUN echo '# Test .bashrc from Docker A' > /home/tester/.bashrc && \
    echo 'export PATH=$HOME/.local/bin:$PATH' >> /home/tester/.bashrc && \
    echo 'export EDITOR=vim' >> /home/tester/.bashrc && \
    echo '# My bash aliases' > /home/tester/.bash_aliases && \
    echo 'alias ll="ls -la"' >> /home/tester/.bash_aliases && \
    echo 'alias gs="git status"' >> /home/tester/.bash_aliases && \
    echo '[user]' > /home/tester/.gitconfig && \
    echo '    name = Test User' >> /home/tester/.gitconfig && \
    echo '    email = test@example.com' >> /home/tester/.gitconfig && \
    echo '[core]' >> /home/tester/.gitconfig && \
    echo '    editor = vim' >> /home/tester/.gitconfig && \
    echo '[init]' >> /home/tester/.gitconfig && \
    echo '    defaultBranch = main' >> /home/tester/.gitconfig && \
    mkdir -p /home/tester/.ssh && \
    echo 'Host gitlab.com' > /home/tester/.ssh/config && \
    echo '    User git' >> /home/tester/.ssh/config && \
    echo '    IdentityFile ~/.ssh/id_rsa' >> /home/tester/.ssh/config && \
    echo '# Test vimrc' > /home/tester/.vimrc && \
    echo 'set number' >> /home/tester/.vimrc && \
    echo 'syntax on' >> /home/tester/.vimrc && \
    echo 'set tabstop=4' >> /home/tester/.vimrc

ENTRYPOINT ["bash"]
