use v6.e.PREVIEW

use Pandoc;
use JSON::Class:auth<zef:vrurg>;

use DB::Post;

#| An empty placeholder post
unit class PlaceholderPost does Post is json(:pretty);

#| Marker for disambiguation between post types in json representation, the
#| cheaty way
has Bool:D $.placeholder = True;

#| An optional body for the placeholder post
has Str $.body;

method title(--> Str:D) {
    "Placeholder Article"
}

#| Shortcut for creating an empty placeholder post
method empty(--> PlaceholderPost:D) {
    PlaceholderPost.new(
        source => "/dev/null".IO,
        posted-at => DateTime.now,
        hidden => True,
    )
}

# Override the all-slugs method to return an empty array, we don't want the
# placeholder article to be refered to as anything but its id
method all-slugs(--> Array[Str:D]) {
    Array[Str:D].new
}

# Return the body if there is one, the empty string if there isn't one
method render-html(--> Str:D) {
    $!body // ''
}