"""
Tests for the Tano Shield package
"""

import unittest
from unittest.mock import patch, MagicMock
from tano_shield import TanoShield, FirewallClient, PIIClient
from tano_shield.core.errors import ValidationError

class TestTanoShield(unittest.TestCase):
    """Test the TanoShield main client"""
    
    def setUp(self):
        """Set up test fixtures"""
        self.api_key = 'test-api-key'
        self.tano_shield = TanoShield(api_key=self.api_key)
    
    def test_initialization(self):
        """Test client initialization"""
        self.assertEqual(self.tano_shield.options['api_key'], self.api_key)
        self.assertIsInstance(self.tano_shield.firewall, FirewallClient)
        self.assertIsInstance(self.tano_shield.pii, PIIClient)
    
    def test_set_api_key(self):
        """Test setting API key"""
        new_api_key = 'new-test-api-key'
        self.tano_shield.set_api_key(new_api_key)
        self.assertEqual(self.tano_shield.options['api_key'], new_api_key)
        self.assertEqual(self.tano_shield.client.api_key, new_api_key)
        self.assertEqual(self.tano_shield.firewall.api_key, new_api_key)
        self.assertEqual(self.tano_shield.pii.api_key, new_api_key)

class TestFirewallClient(unittest.TestCase):
    """Test the FirewallClient"""
    
    def setUp(self):
        """Set up test fixtures"""
        self.api_key = 'test-api-key'
        self.firewall = FirewallClient(api_key=self.api_key)
    
    @patch('tano_shield.core.client.TanoShieldClient.post')
    def test_check_input(self, mock_post):
        """Test check_input method"""
        # Setup mock
        mock_response = {'overallSafe': True, 'checks': []}
        mock_post.return_value = mock_response
        
        # Call method
        result = self.firewall.check_input(user_input='Test input')
        
        # Assertions
        self.assertEqual(result, mock_response)
        mock_post.assert_called_once()
        
        # Test validation
        with self.assertRaises(ValidationError):
            self.firewall.check_input(user_input='')

class TestPIIClient(unittest.TestCase):
    """Test the PIIClient"""
    
    def setUp(self):
        """Set up test fixtures"""
        self.api_key = 'test-api-key'
        self.pii = PIIClient(api_key=self.api_key)
    
    @patch('tano_shield.core.client.TanoShieldClient.post')
    def test_redact_text(self, mock_post):
        """Test redact_text method"""
        # Setup mock
        mock_response = {'redactedText': 'Redacted text', 'entities': []}
        mock_post.return_value = mock_response
        
        # Call method
        result = self.pii.redact_text(text='Test text')
        
        # Assertions
        self.assertEqual(result, mock_response)
        mock_post.assert_called_once()
        
        # Test validation
        with self.assertRaises(ValidationError):
            self.pii.redact_text(text='')

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