"""
📦 Delimiters advanced add-ons for Telethon
👤 Created by Ankit Chaubey | https://github.com/ankit-chaubey/delimiters
© 2026 Ankit Chaubey. All rights reserved.
📬 Contact: m.ankitchaubey@gmail.com | Telegram: @ankify @AnkitChaubey @ChaubeyBot
⚠️ Warning: Do not edit this file unless you are absolutely sure what you are doing.
💥 Changing this file may break the package.
🚀 Initially built for personal use, now released publicly.
"""

from typing import Iterable, Tuple, List
from telethon.tl.types import TypeMessageEntity

from .custom_markdown import CustomMarkdown
from .html_ext import CustomHtmlParser


def parse(
    text: str,
    *,
    mode: str = "md",
) -> Tuple[str, List[TypeMessageEntity]]:
    if not text:
        return text, []

    mode = mode.lower()

    if mode in ("md", "markdown"):
        return CustomMarkdown.parse(text)

    if mode == "html":
        return CustomHtmlParser.parse(text)

    raise ValueError(f"Unknown parse mode: {mode!r}")


def unparse(
    text: str,
    entities: Iterable[TypeMessageEntity],
    *,
    mode: str = "md",
) -> str:
    if not text:
        return text

    mode = mode.lower()

    if mode in ("md", "markdown"):
        return CustomMarkdown.unparse(text, entities)

    if mode == "html":
        return CustomHtmlParser.unparse(text, entities)

    raise ValueError(f"Unknown unparse mode: {mode!r}")
