"""Agent layer Dockerfile generation.

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

from __future__ import annotations

from typing import TYPE_CHECKING

from paude.constants import CONTAINER_ENTRYPOINT, CONTAINER_HOME

if TYPE_CHECKING:
    from paude.agents.base import Agent


def generate_claude_layer_dockerfile(agent: Agent | None = None) -> str:
    """Generate a Dockerfile that adds the CLI agent to a base image.

    Args:
        agent: Agent instance. If None, uses Claude defaults.

    Returns:
        Dockerfile content that installs the agent on top of BASE_IMAGE.
    """
    if agent is None:
        from paude.agents import get_agent

        agent = get_agent("claude")

    lines: list[str] = []

    lines.append("# Auto-generated by paude - DO NOT EDIT")
    display = agent.config.display_name
    lines.append(f"# This layer adds {display} to the base paude image")
    lines.append("ARG BASE_IMAGE")
    lines.append("FROM ${BASE_IMAGE}")

    lines.extend(agent.dockerfile_install_lines(CONTAINER_HOME))

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

    return "\n".join(lines)
