using System.Text.Json.Serialization;
namespace Elternbeirat.Contracts;
///
/// A single question and answer of the FAQ, as stored in PocketBase.
///
///
/// On the FAQ page, entries are grouped by their . The topic is
/// a PocketBase relation; is the resolved topic record, present
/// only when the query expanded the relation (see ).
///
public record Faq
{
///
/// 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 question as a parent would phrase it.
///
///
/// : a FAQ entry without a question is incomplete, and
/// the field is required in PocketBase.
///
[JsonPropertyName("question")]
public required string Question { get; init; }
///
/// Gets the answer as Markdown.
///
///
/// : a FAQ entry exists to answer its question, so an
/// entry without an answer is incomplete. The field is required in PocketBase.
///
[JsonPropertyName("answer")]
public required string Answer { get; init; }
///
/// Gets the expanded relations returned by PocketBase, or
/// when the query did not expand any.
///
[JsonPropertyName("expand")]
public FaqExpand? Expand { get; init; }
///
/// Gets the resolved topic this entry is grouped under, or
/// when the query did not expand the topic relation.
///
///
/// Convenience over : the FAQ page reads the grouping
/// heading from here. It is unless the entry was loaded
/// with the topic relation expanded.
///
[JsonIgnore]
public FaqTopic? Topic => Expand?.Topic;
}
///
/// The relations of a that PocketBase returns under
/// expand when the query asks for them.
///
///
/// One property per expandable relation, named after its PocketBase field, so the
/// JSON expand object maps straight onto it. reads
/// through this.
///
public record FaqExpand
{
///
/// Gets the expanded topic of the topic relation, if it was expanded.
///
[JsonPropertyName("topic")]
public FaqTopic? Topic { get; init; }
}