# Copyright (c) Huawei Technologies Co., Ltd. 2026-2026. All rights reserved.
# OpenOLC is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#         `http://license.coscl.org.cn/MulanPSL2`
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.

import sys
import unittest
from unittest.mock import patch, MagicMock

from olc.control.matcher.group_matcher import GroupMatcher
from olc.control.matcher.policy_matcher import FlowMatcher

if "olc.control.matcher.matcher_provider" in sys.modules:
    del sys.modules["olc.control.matcher.matcher_provider"]

with patch("olc.control.matcher.policy_matcher.Event") as _mock_event:
    _mock_event.get_instance.return_value.olc_clean_rule = MagicMock()
    from olc.control.matcher.matcher_provider import OlcMatcherProvider


class TestOlcMatcherProvider(unittest.TestCase):

    def test_get_group_matcher_returns_group_matcher_instance(self):
        matcher = OlcMatcherProvider.get_group_matcher()
        self.assertIsInstance(matcher, GroupMatcher)

    def test_get_flow_matcher_returns_flow_matcher_instance(self):
        matcher = OlcMatcherProvider.get_flow_matcher()
        self.assertIsInstance(matcher, FlowMatcher)

    def test_get_group_matcher_returns_same_instance(self):
        matcher1 = OlcMatcherProvider.get_group_matcher()
        matcher2 = OlcMatcherProvider.get_group_matcher()
        self.assertIs(matcher1, matcher2)

    def test_get_flow_matcher_returns_same_instance(self):
        matcher1 = OlcMatcherProvider.get_flow_matcher()
        matcher2 = OlcMatcherProvider.get_flow_matcher()
        self.assertIs(matcher1, matcher2)

    def test_class_has_group_matcher_attribute(self):
        self.assertTrue(hasattr(OlcMatcherProvider, "group_matcher"))
        self.assertIsInstance(OlcMatcherProvider.group_matcher, GroupMatcher)

    def test_class_has_flow_matcher_attribute(self):
        self.assertTrue(hasattr(OlcMatcherProvider, "flow_matcher"))
        self.assertIsInstance(OlcMatcherProvider.flow_matcher, FlowMatcher)

    def test_get_group_matcher_is_classmethod(self):
        self.assertTrue(
            isinstance(OlcMatcherProvider.__dict__["get_group_matcher"], classmethod)
        )

    def test_get_flow_matcher_is_classmethod(self):
        self.assertTrue(
            isinstance(OlcMatcherProvider.__dict__["get_flow_matcher"], classmethod)
        )


if __name__ == "__main__":
    unittest.main()