"""Tests for CLI helper functions."""

from fwauto.cli import _build_deploy_state, _build_log_state


class TestBuildDeployState:
    """Test _build_deploy_state helper function."""

    def test_build_deploy_state_basic(self):
        state = _build_deploy_state("test.hex", "/project", "am62x")

        assert state["execution_mode"] == "deploy"
        assert state["command"] == "deploy"
        assert state["command_args"]["binary_args"] == "test.hex"
        assert state["project_root"] == "/project"
        assert state["platform"] == "am62x"
        assert state["project_initialized"] is True

    def test_build_deploy_state_empty_binary_args(self):
        state = _build_deploy_state("", "/project", "stm32_keil")

        assert state["command_args"]["binary_args"] == ""
        assert state["platform"] == "stm32_keil"


class TestBuildLogState:
    """Test _build_log_state helper function."""

    def test_build_log_state_basic(self):
        state = _build_log_state("uart.log", "分析 log", "/project", "am62x")

        assert state["execution_mode"] == "log"
        assert state["command"] == "log"
        assert state["user_prompt"] == "分析 log"
        assert state["project_root"] == "/project"
        assert state["platform"] == "am62x"
        assert state["project_initialized"] is True

    def test_build_log_state_double_storage(self):
        """Verify double storage pattern for log_file_path."""
        state = _build_log_state("uart.log", "分析", "/project", "am62x")

        # Both fields should contain the log path
        assert state["log_file_path"] == "uart.log"
        assert state["command_args"]["log_path"] == "uart.log"
        assert state["command_args"]["analysis_prompt"] == "分析"

    def test_build_log_state_cjk_prompt(self):
        """Test with CJK characters in prompt."""
        state = _build_log_state(
            "test.log",
            "有任何 error 嗎？LED 閃爍頻率是多少？",
            "/project",
            "raspberry-pi",
        )

        assert state["user_prompt"] == "有任何 error 嗎？LED 閃爍頻率是多少？"
        assert state["platform"] == "raspberry-pi"
