def normalize_text(text: str) -> str:
    return " ".join(text.lower().strip().split())


class IntentService:
    def __init__(self, flows: list[dict]):
        self.flows = flows

    def detect_issue(self, user_message: str):
        text = normalize_text(user_message)

        for flow in self.flows:
            for keyword in flow.get("trigger_keywords", []):
                if normalize_text(keyword) in text:
                    return flow

        for flow in self.flows:
            title = flow.get("issue_title", "")
            if title and normalize_text(title) in text:
                return flow

        return None