"""
Tano Shield PII Redaction Client
"""

from tano_shield.core import TanoShieldClient
from tano_shield.core.errors import ValidationError

class PIIClient(TanoShieldClient):
    """
    PII Redaction client for Tano Shield
    """
    
    def __init__(self, **options):
        """
        Create a new PII Redaction client
        
        Args:
            **options: Client options
        """
        super().__init__(**options)
    
    def redact_text(self, text, entity_types=None, mask_mode=False):
        """
        Redact PII from text
        
        Args:
            text (str): The text to redact
            entity_types (list, optional): Specific entity types to redact
            mask_mode (bool, optional): Whether to mask entities instead of removing them
        
        Returns:
            dict: Redaction results
        
        Raises:
            ValidationError: If text is not provided
        """
        if not text:
            raise ValidationError('Text is required')
        
        payload = {
            'text': text,
            'entity_types': entity_types,
            'mask_mode': mask_mode,
        }
        
        return self.post(self.endpoints['PII_REDACTION'], payload)
    
    def detect_pii(self, text, entity_types=None):
        """
        Detect PII in text without redacting
        
        Args:
            text (str): The text to analyze
            entity_types (list, optional): Specific entity types to detect
        
        Returns:
            dict: Detection results
        
        Raises:
            ValidationError: If text is not provided
        """
        if not text:
            raise ValidationError('Text is required')
        
        payload = {
            'text': text,
            'entity_types': entity_types,
            'detect_only': True,
        }
        
        return self.post(self.endpoints['PII_REDACTION'], payload)
    
    def get_supported_entity_types(self):
        """
        Get supported PII entity types
        
        Returns:
            list: List of supported entity types
        """
        return self.get(f"{self.endpoints['PII_REDACTION']}/entity-types")