from __future__ import annotations

from dataclasses import dataclass


@dataclass(frozen=True)
class DataikuInstallPlan:
    """Plan inputs for installing Dataiku DSS (Design, Automation, or Govern node)."""

    version: str
    os_user: str
    os_group: str
    root_dir: str
    install_dir: str
    data_dir: str
    dss_port: int
    node_type: str = "design"  # "design", "automation", or "govern"
    archive_path: str | None = None  # local file path for offline/air-gapped upload
    install_docker: bool = False
    docker_data_root: str | None = None
    install_r: bool = False
    r_repo: str | None = None  # CRAN mirror URL for proxy R installs
    r_pkg_dir: str | None = None  # local dir with pre-downloaded R packages (air-gapped)
    os_user_password: str | None = None  # password to set for the OS user

    install_kubectl: bool = True
    add_to_docker_group: bool = False

    # Govern node (requires PostgreSQL and a JDBC driver)
    with_jdbc: bool = False
    govern_jdbc_url: str | None = None
    govern_jdbc_user: str | None = None
    govern_jdbc_password: str | None = None  # discouraged; prefer prompting
    govern_init_db: bool = True
    encrypt_govern_password: bool = True

    @property
    def archive_url(self) -> str:
        """Auto-generated download URL from version (like Nexus pattern)."""
        return f"https://downloads.dataiku.com/public/dss/{self.version}/dataiku-dss-{self.version}.tar.gz"

    @property
    def archive_remote_path(self) -> str:
        return f"{self.install_dir.rstrip('/')}/dataiku-dss-{self.version}.tar.gz"

    @property
    def extracted_dir(self) -> str:
        return f"{self.install_dir.rstrip('/')}/dataiku-dss-{self.version}"

