using System.Text.Json.Serialization;
namespace Elternbeirat.Contracts;
///
/// A news post of the site, as stored in PocketBase.
///
///
/// Post lists are ordered by , newest first.
///
public record Post
{
///
/// Gets the PocketBase record id.
///
///
/// : every stored record has an id. Modeling it as
/// required states which fields a record must carry, independent of the store,
/// so a future data source has to supply them too.
///
[JsonPropertyName("id")]
public required string Id { get; init; }
///
/// Gets the publication date as a calendar day.
///
///
/// A post's date is a plain day, not a point in time. It is read as the
/// Berlin calendar day: the UTC value is converted to Europe/Berlin and only
/// the day is kept, so the day an editor picked is the day shown -- no
/// time-of-day, no off-by-one at midnight. See .
///
[JsonPropertyName("date")]
[JsonConverter(typeof(DateOnlyConverter))]
public DateOnly Date { get; init; }
///
/// Gets the heading shown to visitors.
///
///
/// Free text; may contain umlauts and spaces. For the URL, see .
/// : a post without a heading is incomplete, and the
/// field is required in PocketBase.
///
[JsonPropertyName("title")]
public required string Title { get; init; }
///
/// Gets the post body as Markdown.
///
[JsonPropertyName("body")]
public string Body { get; init; } = string.Empty;
///
/// Gets the URL slug of the post, e.g. "herbstbasar" for /posts/herbstbasar.
///
///
/// A URL path segment: lowercase letters, digits and single hyphens as
/// separators, no umlauts. PocketBase enforces this on save via a field
/// pattern (^[a-z0-9]+(-[a-z0-9]+)*$), so every stored slug is already
/// canonical and the app can use it verbatim in comparisons and generated URLs.
///
///
/// : the slug is how a post is addressed, so a record
/// without one is broken. It is a required field in PocketBase, so deserializing
/// one that lacks it should fail loudly rather than yield a post with no URL.
///
[JsonPropertyName("slug")]
public required string Slug { get; init; }
}