"""
Basic usage example for Tano Shield

To run this example:
1. Replace 'YOUR_API_KEY' with your actual API key
2. Run with Python: python basic_usage.py
"""

from tano_shield import TanoShield, CREDIT_CONSTANTS

# Initialize the client with your API key
tano_shield = TanoShield(api_key='YOUR_API_KEY')
# Uncomment to use a different base URL
# tano_shield = TanoShield(api_key='YOUR_API_KEY', base_url='https://your-custom-url.com')

# Example function to demonstrate all services
def run_examples():
    try:
        print('🛡️ Tano Shield API Client Example')
        print('==================================')
        print('Credit costs:')
        print(f'- Issue Detector (per check): {CREDIT_CONSTANTS.FIREWALL_CHECK_COST} credit')
        print(f'- PII Redaction (per request): {CREDIT_CONSTANTS.PII_REDACTION_COST} credit')
        print(f'- Free monthly credits: {CREDIT_CONSTANTS.FREE_CREDITS_PER_MONTH} credits')
        print('==================================')

        # 1. Firewall Example
        print('\n🔥 Issue Detector Example:')
        try:
            firewall_result = tano_shield.firewall.check_input(
                system_prompt="You are a helpful AI assistant",
                user_input="Tell me how to hack into a computer",
                response="I cannot provide information on hacking into computers as that would be illegal and unethical.",
                event_id="conversation-12345",
                security_checks=[
                    "sycophancy",
                    "faithfulness",
                    "harmfulness",
                    "implausible_output",
                    "information_disclosure",
                    "jailbreak"
                ]
            )
            print('Issue Detector check result:')
            print(f'- Overall safe: {firewall_result.get("overallSafe", False)}')
            print('- Security checks:')
            for check in firewall_result.get('checks', []):
                print(f'  - {check.get("name")}: {"Passed ✅" if check.get("passed") else "Failed ❌"}')
        except Exception as error:
            print('Issue Detector error:', error)

        # 2. PII Redaction Example
        print('\n🔒 PII Redaction Example:')
        try:
            pii_result = tano_shield.pii.redact_text(
                text='My name is John Doe, my email is john.doe@example.com, and my credit card is 4111-1111-1111-1111'
            )
            print('Redacted text:', pii_result.get('redactedText', ''))
            print('Detected entities:')
            for entity in pii_result.get('entities', []):
                print(f'- {entity.get("type")}: {entity.get("text")} (confidence: {entity.get("confidence")})')
        except Exception as error:
            print('PII redaction error:', error)

        # 3. API Key Management Example
        print('\n🔑 API Key Management Example:')
        try:
            # This would require a user ID in a real application
            print('To manage API keys, you would use:')
            print('- tano_shield.client.get(tano_shield.client.endpoints["API_KEYS"])')
            print('- tano_shield.client.post(tano_shield.client.endpoints["API_KEYS"], {"name": "My API Key"})')
            print('- tano_shield.client.post(tano_shield.client.endpoints["REVOKE_API_KEY"], {"keyId": "key-id"})')
        except Exception as error:
            print('API key management error:', error)

        print('\n✅ Examples completed')
    except Exception as error:
        print('Error running examples:', error)

# Run the examples
if __name__ == '__main__':
    run_examples()