from app.repositories.clickhouse_repository import ClickHouseRepository


class ReportService:
    def __init__(self, clickhouse_repo: ClickHouseRepository):
        self.clickhouse = clickhouse_repo

    def agent_report(self, tenant_id: str, agent_id: str):
        total, avg_q, compliance = self.clickhouse.get_agent_report(tenant_id, agent_id)
        recurring = self.clickhouse.get_recurring_issues(tenant_id, agent_id)

        return {
            'tenant_id': tenant_id,
            'agent_id': agent_id,
            'total_calls_scored': total,
            'avg_quality_score': round(avg_q, 2),
            'compliance_rate': round(compliance, 2),
            'recurring_issues': recurring,
        }
