import pytest
from target_simulator.core.tftp_communicator import TFTPCommunicator
from target_simulator.core.models import Scenario


@pytest.fixture
def tftp_config():
    return {"ip": "127.0.0.1", "port": 69}


def test_tftp_communicator_init():
    comm = TFTPCommunicator()
    assert comm.config is None or isinstance(comm.config, dict)
    assert hasattr(comm, "logger")


def test_tftp_communicator_connect_valid(tftp_config):
    comm = TFTPCommunicator()
    result = comm.connect(tftp_config)
    assert result is True or result is False


def test_tftp_communicator_connect_invalid():
    comm = TFTPCommunicator()
    result = comm.connect({"ip": "127.0.0.1"})  # missing port
    assert result is False


def test_tftp_communicator_send_scenario(tftp_config):
    comm = TFTPCommunicator()
    comm.connect(tftp_config)
    scenario = Scenario(name="TestScenario")
    result = comm.send_scenario(scenario)
    assert result is True or result is False


def test_tftp_communicator_list_available_ports():
    ports = TFTPCommunicator.list_available_ports()
    assert isinstance(ports, list)


def test_tftp_communicator_test_connection(tftp_config):
    result = TFTPCommunicator.test_connection(tftp_config)
    assert result is True or result is False
