from __future__ import annotations

import re


class DocsPathResolver:
    def resolve(self, *, application: str, platform: str, doc_type: str, doc_id: str, domain: str = "") -> str:
        root = self._clean(domain) or self._clean(application) or "common"
        plat = self._clean(platform) or "web"
        dtype = self._clean(doc_type) or "misc"
        did = self._clean(doc_id) or "untitled"
        return f"docs/{root}/{plat}/{dtype}/{did}.md"

    def _clean(self, value: str) -> str:
        normalized = re.sub(r"[^a-zA-Z0-9._-]+", "-", (value or "").strip().lower())
        return normalized.strip(".-")
