Heading.java

package pro.verron.asciidoc.core;

import java.util.List;

import static java.util.Collections.emptyList;

/// Heading block (levels 1..6).
///
/// @param header  AsciiDoc block headers containing optional information
/// @param level   heading level (1..6)
/// @param inlines inline fragments
public record Heading(List<String> header, int level, List<Inline> inlines)
        implements Block {

    /// Constructs a [Heading] without block headers.
    ///
    /// @param level   the heading level, must be between 1 and 6 (inclusive)
    /// @param inlines the inline fragments representing the heading content
    /// @throws IllegalArgumentException if the heading level is outside the range 1..6
    public Heading(int level, List<Inline> inlines) {
        this(emptyList(), level, inlines);
    }

    /// Constructs a [Heading] with block headers.
    ///
    /// @param header  header elements, if any
    /// @param level   the heading level, must be between 1 and 6 (inclusive)
    /// @param inlines the inline fragments representing the heading content
    /// @throws IllegalArgumentException if the heading level is outside the range 1..6
    public Heading(List<String> header, int level, List<Inline> inlines) {
        if (level < 1 || level > 6) throw new IllegalArgumentException(
                "Heading level must be between 1 and 6");
        this.header = List.copyOf(header);
        this.level = level;
        this.inlines = List.copyOf(inlines);
    }

    @Override
    public int size() {
        return 1;
    }
}