class ExplainService:
    def add_explanations(self, resumes, ranked, job_description):
        rank_map = {r["resume_id"]: r["final_score"] for r in ranked}
        results = []

        for r in resumes:
            score = rank_map[r["resume_id"]]

            # simple rule-based explanation stub
            skills = r.get("skills", [])
            required = self.extract_required_skills(job_description)

            strengths = [s for s in skills if s in required]
            weaknesses = [s for s in required if s not in skills]

            results.append(
                {
                    "resume_id": r["resume_id"],
                    "name": r.get("name"),
                    "match_score": round(score * 100, 2),
                    "strengths": strengths,
                    "weaknesses": weaknesses,
                }
            )

        return results

    def extract_required_skills(self, jd):
        # crude extractor; replace with NLP/LLM
        return [s.strip().lower() for s in ["python", "java", "aws", "docker"]]
