from typing import Any

from temporalio.testing import ActivityEnvironment

from csirtmu.beta_temporal.external_services.rt import structs
from csirtmu.beta_temporal.workflows.change_subject_of_automatic_report_on_correspond import (
    ChangeSubjectOfAutomaticReportOnCorrespondActivities,
)


class TestIsAutomaticReport:
    async def test_is_automatic_report_true(
        self,
        mock_transaction_obj: structs.TransactionStruct,
        test_activity_env: ActivityEnvironment,
        mock_rt_client: Any,
    ) -> None:
        assert mock_transaction_obj.ticket_obj is not None
        mock_transaction_obj.interface = "email"
        mock_transaction_obj.ticket_obj.subject = "Automatic ticket placeholder"

        activities = ChangeSubjectOfAutomaticReportOnCorrespondActivities(mock_rt_client)

        res = await test_activity_env.run(activities.is_automatic_report, mock_transaction_obj)
        assert res

    async def test_is_automatic_report_ticket_none(
        self,
        mock_transaction_obj: structs.TransactionStruct,
        test_activity_env: ActivityEnvironment,
        mock_rt_client: Any,
    ) -> None:
        mock_transaction_obj.ticket_obj = None

        activities = ChangeSubjectOfAutomaticReportOnCorrespondActivities(mock_rt_client)

        res = await test_activity_env.run(activities.is_automatic_report, mock_transaction_obj)
        assert not res

    async def test_is_automatic_report_interface_none(
        self,
        mock_transaction_obj: structs.TransactionStruct,
        test_activity_env: ActivityEnvironment,
        mock_rt_client: Any,
    ) -> None:
        assert mock_transaction_obj.ticket_obj is not None
        mock_transaction_obj.interface = None

        activities = ChangeSubjectOfAutomaticReportOnCorrespondActivities(mock_rt_client)

        res = await test_activity_env.run(activities.is_automatic_report, mock_transaction_obj)
        assert not res

    async def test_is_automatic_report_wrong_interface(
        self,
        mock_transaction_obj: structs.TransactionStruct,
        test_activity_env: ActivityEnvironment,
        mock_rt_client: Any,
    ) -> None:
        assert mock_transaction_obj.ticket_obj is not None
        mock_transaction_obj.interface = "web"

        activities = ChangeSubjectOfAutomaticReportOnCorrespondActivities(mock_rt_client)

        res = await test_activity_env.run(activities.is_automatic_report, mock_transaction_obj)
        assert not res

    async def test_is_automatic_report_wrong_subject(
        self,
        mock_transaction_obj: structs.TransactionStruct,
        test_activity_env: ActivityEnvironment,
        mock_rt_client: Any,
    ) -> None:
        assert mock_transaction_obj.ticket_obj is not None
        mock_transaction_obj.interface = "email"
        mock_transaction_obj.ticket_obj.subject = "Random subject"

        activities = ChangeSubjectOfAutomaticReportOnCorrespondActivities(mock_rt_client)

        res = await test_activity_env.run(activities.is_automatic_report, mock_transaction_obj)
        assert not res
