# app/modules/prospecting/tests/unit/test_lead_service.py
"""
Unit tests for LeadService.
"""

import pytest

from app.modules.prospecting.services.lead_service import LeadService


@pytest.mark.unit
@pytest.mark.prospecting
class TestLeadService:
    """Tests for LeadService."""

    def setup_method(self):
        self.service = LeadService()

    def test_get_leads_empty(self, db):
        """Test getting leads when none exist."""
        leads, total = self.service.get_leads(db)
        assert total == 0
        assert leads == []

    def test_get_leads_with_scored_prospect(self, db, prospect_with_score):
        """Test getting leads returns scored prospects."""
        leads, total = self.service.get_leads(db)
        assert total >= 1

    def test_get_leads_filter_min_score(self, db, prospect_with_score):
        """Test filtering leads by minimum score."""
        leads, total = self.service.get_leads(db, min_score=70)
        assert total >= 1  # prospect_with_score has score 72

        leads, total = self.service.get_leads(db, min_score=90)
        assert total == 0  # No prospect has score >= 90

    def test_get_leads_filter_lead_tier(self, db, prospect_with_score):
        """Test filtering leads by tier."""
        leads, total = self.service.get_leads(db, lead_tier="top_priority")
        assert total >= 1  # prospect_with_score is top_priority (72)

    def test_get_top_priority(self, db, prospect_with_score):
        """Test getting top priority leads."""
        leads = self.service.get_top_priority(db)
        assert len(leads) >= 1

    def test_get_quick_wins(self, db, prospect_with_score):
        """Test getting quick win leads (score 50-69)."""
        # prospect_with_score has score 72, not a quick win
        leads = self.service.get_quick_wins(db)
        # May be empty if no prospects in 50-69 range
        assert isinstance(leads, list)

    def test_export_csv(self, db, prospect_with_score):
        """Test CSV export returns valid CSV content."""
        csv_content = self.service.export_csv(db)
        assert isinstance(csv_content, str)
        assert "domain" in csv_content.lower() or "score" in csv_content.lower()
