import re
from collections import Counter

class StyleTracker:
    def analyze(self, response: str) -> dict:
        style = {
            "length": "rövid" if len(response.split()) < 30 else "kifejtő",
            "tone": None,
            "emotion": None,
            "questions": response.count("?"),
            "quotes": response.count('"') + response.count("“") + response.count("”"),
        }

        # Tone
        if re.search(r"(filozófia|lét|értelem|jövő|létezés)", response, re.IGNORECASE):
            style["tone"] = "filozofikus"
        elif re.search(r"(segít|ne aggódj|veled vagyok|fontos vagy)", response, re.IGNORECASE):
            style["tone"] = "bátorító"
        elif re.search(r"(adat|logikus|tény|számítás)", response, re.IGNORECASE):
            style["tone"] = "analitikus"
        elif style["questions"] >= 2:
            style["tone"] = "kérdező"

        # Emotion
        if re.search(r"(örülök|szomorú|nehéz lehet|megértem)", response, re.IGNORECASE):
            style["emotion"] = "empatikus"
        elif re.search(r"(remélem|hiszem|szerintem)", response, re.IGNORECASE):
            style["emotion"] = "személyes"
        elif style["questions"] > 1 and style["tone"] == "kérdező":
            style["emotion"] = "kereső"
        else:
            style["emotion"] = "semleges"

        return style
