"""Claude Code layer Dockerfile generation.

This module generates a Dockerfile that adds Claude Code to a base image.
Claude Code is installed at user-side build time (not in the published image)
due to licensing restrictions that prohibit redistribution.
"""

from __future__ import annotations

from paude.constants import CONTAINER_ENTRYPOINT, CONTAINER_HOME


def generate_claude_layer_dockerfile() -> str:
    """Generate a Dockerfile that adds Claude Code to a base image.

    Returns:
        Dockerfile content that installs Claude Code on top of BASE_IMAGE.
    """
    lines: list[str] = []

    lines.append("# Auto-generated by paude - DO NOT EDIT")
    lines.append("# This layer adds Claude Code to the base paude image")
    lines.append("ARG BASE_IMAGE")
    lines.append("FROM ${BASE_IMAGE}")

    lines.append("")
    lines.append("# Install Claude Code (as paude user)")
    lines.append("USER paude")
    lines.append(f"WORKDIR {CONTAINER_HOME}")
    lines.append("RUN curl -fsSL https://claude.ai/install.sh | bash")

    lines.append("")
    lines.append("# Disable auto-updates (version controlled by image rebuild)")
    lines.append("ENV DISABLE_AUTOUPDATER=1")

    lines.append("")
    lines.append("# Ensure claude is in PATH")
    lines.append(f'ENV PATH="{CONTAINER_HOME}/.local/bin:$PATH"')

    lines.append("")
    lines.append("# Fix permissions for OpenShift arbitrary UID compatibility")
    lines.append("USER root")
    lines.append(f"RUN chmod -R g+rwX {CONTAINER_HOME}")

    lines.append("")
    lines.append("USER paude")
    lines.append(f"WORKDIR {CONTAINER_HOME}")
    lines.append(f'ENTRYPOINT ["{CONTAINER_ENTRYPOINT}"]')

    return "\n".join(lines)
