using System.Text.Json.Serialization;
namespace Elternbeirat.Contracts;
///
/// A content page of the site, as stored in PocketBase.
///
///
/// Pages also drive the site navigation: and
/// decide where and in which order a page appears in the
/// header or footer menu. lists dynamic blocks rendered
/// below the page body.
///
public record Page
{
///
/// The slug of the home page, which is served at the site root / rather
/// than at /home. Reserved: no other page may use it.
///
private const string HomeSlug = "home";
///
/// Gets the PocketBase record id.
///
[JsonPropertyName("id")]
public string Id { get; init; } = "";
///
/// Gets the heading shown to visitors.
///
///
/// Free text; may contain umlauts and spaces. For the URL, see .
///
[JsonPropertyName("title")]
public string Title { get; init; } = "";
///
/// Gets the page body as Markdown.
///
[JsonPropertyName("body")]
public string Body { get; init; } = "";
///
/// Gets the navigation menu the page appears in.
///
///
/// Either "header" or "footer".
///
[JsonPropertyName("location")]
public string Location { get; init; } = "";
///
/// Gets the sort order within the navigation menu given by .
///
///
/// The sort key; pages with smaller values appear first.
///
[JsonPropertyName("order")]
public double Order { get; init; }
///
/// Gets the URL slug of the page, e.g. "board" for /board.
///
///
/// A lowercase path segment without umlauts.
///
[JsonPropertyName("slug")]
public string Slug { get; init; } = "";
///
/// Gets the dynamic blocks rendered below the .
///
///
/// Any of "posts", "events" and "faqs", or an empty list
/// for a plain text page.
///
[JsonPropertyName("embed")]
public IReadOnlyList Embed { get; init; } = [];
///
/// Gets a value indicating whether the page is visible to visitors of the site.
///
[JsonPropertyName("public")]
public bool Public { get; init; }
///
/// Tests whether a slug is the home page's, ignoring case. This is the single
/// definition of that comparison, so every caller treats home and
/// Home alike.
///
///
/// The slug to test.
///
///
/// if is the home page's slug.
///
public static bool IsHomeSlug(string slug) =>
string.Equals(slug, HomeSlug, StringComparison.OrdinalIgnoreCase);
}