import pytest_mock
from temporalio.testing import ActivityEnvironment

from csirtmu.beta_temporal.config import Config as WorkerConfig
from csirtmu.beta_temporal.external_services.rt import structs
from csirtmu.beta_temporal.external_services.rt.client import RTClient
from csirtmu.beta_temporal.workflows.link_with_ticket_on_link_with_header import (
    LinkWithTicketOnLinkWithHeaderActivities,
)


class TestHasLinkWithHeader:
    async def test_has_link_with_header_ticket_data_is_none(
        self,
        worker_config: WorkerConfig,
        mock_transaction_obj: structs.TransactionStruct,
        test_activity_env: ActivityEnvironment,
        mocker: pytest_mock.MockerFixture,
    ) -> None:
        activities = LinkWithTicketOnLinkWithHeaderActivities(RTClient(worker_config.rt))
        get_ticket_data_mock = mocker.patch(
            "csirtmu.beta_temporal.workflows.link_with_ticket_on_link_with_header.RTClient.get_ticket_data",
        )
        get_ticket_data_mock.return_value = None
        assert not await test_activity_env.run(activities.has_link_with_header, mock_transaction_obj)

    async def test_has_link_with_header_false(
        self,
        worker_config: WorkerConfig,
        mock_transaction_obj: structs.TransactionStruct,
        test_activity_env: ActivityEnvironment,
        mock_ticket_data: structs.TicketData,
        mocker: pytest_mock.MockerFixture,
    ) -> None:
        activities = LinkWithTicketOnLinkWithHeaderActivities(RTClient(worker_config.rt))
        get_ticket_data_mock = mocker.patch(
            "csirtmu.beta_temporal.workflows.link_with_ticket_on_link_with_header.RTClient.get_ticket_data",
        )
        get_ticket_data_mock.return_value = mock_ticket_data
        assert not await test_activity_env.run(activities.has_link_with_header, mock_transaction_obj)

    async def test_has_link_with_header_true(
        self,
        worker_config: WorkerConfig,
        mock_transaction_obj: structs.TransactionStruct,
        test_activity_env: ActivityEnvironment,
        mock_ticket_data: structs.TicketData,
        mocker: pytest_mock.MockerFixture,
    ) -> None:
        activities = LinkWithTicketOnLinkWithHeaderActivities(RTClient(worker_config.rt))
        get_ticket_data_mock = mocker.patch(
            "csirtmu.beta_temporal.workflows.link_with_ticket_on_link_with_header.RTClient.get_ticket_data",
        )
        mock_ticket_data.headers.add_header("X-RT-Link-With", "1")
        get_ticket_data_mock.return_value = mock_ticket_data
        assert await test_activity_env.run(activities.has_link_with_header, mock_transaction_obj)
