#pragma once
#include <string>
#include <unordered_map>
#include <variant>
#include <vector>

namespace fn_md {

/// A YAML value: absent, scalar string, or list of strings.
using YamlValue = std::variant<std::monostate, std::string, std::vector<std::string>>;

/// Result of parsing a Markdown file that may contain a YAML frontmatter block.
struct Frontmatter {
    std::unordered_map<std::string, YamlValue> fields;
    std::string body;         ///< content after the closing `---` line
    bool        has_frontmatter = false;
};

/// Parse a Markdown file that may (or may not) begin with a YAML frontmatter
/// block delimited by `---` lines.
///
/// Supported YAML subset (flat only, no nested maps):
///   key: value              -> string (bare, or "quoted", or 'quoted')
///   key: [a, b, c]          -> inline list  -> vector<string>
///   key:                    -> block list when the next indented lines are
///     - item                   `  - item`   -> vector<string>
///   key: |                  -> unsupported block scalar; stored as ""
///   # comment               -> ignored (also inline trailing comments)
///
/// Notes:
/// - Keys and values are trimmed of leading/trailing whitespace.
/// - A value like `description: "foo: bar"` splits on the FIRST colon only.
/// - Pure function: no I/O, no logging, no side-effects.
Frontmatter parse_md_frontmatter(const std::string& content);

} // namespace fn_md
