//! Markdown to Discord format conversion.
//!
//! Discord supports standard Markdown natively, so unlike Slack we only need
//! minimal adjustments (e.g. truncating messages that exceed Discord's limit).

/// Convert Markdown text to Discord-compatible format.
///
/// Discord supports most standard Markdown:
/// - `**bold**`, `*italic*`, `~~strikethrough~~`
/// - `` `code` `` and ````code blocks````
/// - `> blockquotes`
/// - `[text](url)` links
///
/// The main adjustment is ensuring messages stay within Discord's 2000-char
/// limit.  Actual truncation is handled by the transport layer; this function
/// performs any lightweight text normalization needed.
pub fn markdown_to_discord(text: &str) -> String {
    use crate::chat::util::normalize_line_breaks;
    normalize_line_breaks(text)
}

// ── Tests ───────────────────────────────────────────────────────────────

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn discord_plain_text_unchanged() {
        let plain = "Hello, this is a plain message.";
        assert_eq!(markdown_to_discord(plain), plain);
    }

    #[test]
    fn discord_bold_preserved() {
        assert_eq!(markdown_to_discord("**bold text**"), "**bold text**");
    }

    #[test]
    fn discord_code_block_preserved() {
        let input = "```rust\nlet x = 1;\n```";
        assert_eq!(markdown_to_discord(input), input);
    }

    #[test]
    fn discord_empty_string_unchanged() {
        assert_eq!(markdown_to_discord(""), "");
    }

    #[test]
    fn discord_link_preserved() {
        let input = "[click here](https://example.com)";
        assert_eq!(markdown_to_discord(input), input);
    }
}
