"""Tests for agntor.redact — offline PII and secrets redaction."""

from agntor import redact


class TestRedactEmails:
    def test_single_email(self):
        r = redact("Contact john@example.com for details")
        assert "[EMAIL]" in r.redacted
        assert "john@example.com" not in r.redacted
        assert len(r.findings) == 1
        assert r.findings[0].type == "email"

    def test_multiple_emails(self):
        r = redact("Email alice@foo.com or bob@bar.org")
        assert r.redacted.count("[EMAIL]") == 2


class TestRedactCreditCards:
    def test_basic_card(self):
        r = redact("Card: 4111 1111 1111 1111")
        assert "[CREDIT_CARD]" in r.redacted
        assert "4111" not in r.redacted


class TestRedactSSN:
    def test_ssn(self):
        r = redact("SSN: 123-45-6789")
        assert "[SSN]" in r.redacted
        assert "123-45-6789" not in r.redacted


class TestRedactAWSKeys:
    def test_aws_key(self):
        r = redact("Key: AKIAIOSFODNN7EXAMPLE")
        assert "[AWS_KEY]" in r.redacted
        assert "AKIAIOSFODNN" not in r.redacted


class TestRedactAPIKeys:
    def test_generic_api_key(self):
        r = redact("api_key=sk_live_abcdefghijklmnopqrst")
        assert "[REDACTED]" in r.redacted
        assert "sk_live_abcdefghijklmnopqrst" not in r.redacted

    def test_bearer_token(self):
        r = redact("Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.payload.signature")
        assert "Bearer [REDACTED]" in r.redacted


class TestRedactPhone:
    def test_us_phone(self):
        r = redact("Call me at (555) 123-4567")
        assert "[PHONE]" in r.redacted
        assert "123-4567" not in r.redacted


class TestRedactCrypto:
    def test_hd_path(self):
        r = redact("derivation path: m/44'/60'/0'/0/0")
        assert "[HD_PATH]" in r.redacted


class TestRedactIPv4:
    def test_ipv4(self):
        r = redact("Server at 192.168.1.100")
        assert "[IP_ADDRESS]" in r.redacted
        assert "192.168.1.100" not in r.redacted


class TestRedactPassthrough:
    def test_no_pii(self):
        text = "Hello, how are you doing today?"
        r = redact(text)
        assert r.redacted == text
        assert len(r.findings) == 0

    def test_empty_string(self):
        r = redact("")
        assert r.redacted == ""
        assert len(r.findings) == 0


class TestRedactMultiple:
    def test_mixed_pii(self):
        r = redact("Email john@test.com, SSN 123-45-6789, IP 10.0.0.1")
        assert "[EMAIL]" in r.redacted
        assert "[SSN]" in r.redacted
        assert "[IP_ADDRESS]" in r.redacted
        assert len(r.findings) >= 3
