← All source files

V14 / fad4e1a110e5

CalendarModels.cs

Lilith/Core/Calendar/CalendarModels.cs

Unchanged from the preceding version
CS
using System.Text.Json;
using Lilith.Core.Workspace;

namespace Lilith.Core.Calendar;

public sealed record CalendarOptions(string RootDirectory, WorkspaceAccessMode Mode = WorkspaceAccessMode.Ask);
public sealed record CalendarRequest(string Operation, string Id = "", string Title = "", string Date = "",
    string Time = "", string TimeZone = "", string Reminder = "", string Notes = "", string Source = "", string Query = "");
public sealed record CalendarEntry(string Id, string Title, string Date, string Time, string TimeZone,
    DateTimeOffset? StartsUtc, DateTimeOffset? ReminderUtc, string Notes, string Source, int Revision, bool ReminderQueued = false);
public sealed record CalendarProposal(string Id, CalendarRequest Request, int? ExpectedRevision);
public sealed record CalendarNotice(string Id, string EventId, string Title, DateTimeOffset DueUtc, bool Missed, string Message);
public sealed record CalendarResult(string Status, string Message, object? Data = null, string? ProposalId = null)
{
    public string ToReply() => Status == "needs_approval"
        ? $"{Message}\nUse /calendar pending to review the prepared change, then /calendar-approve or /calendar-reject with its proposal ID."
        : Status == "completed" && EventData() is { } entry
            ? $"{Message} {entry.Title}: {entry.Date}{(entry.Time.Length == 0 ? " (all day)" : " at " + entry.Time + " " + entry.TimeZone)}. " +
              (entry.ReminderUtc is { } reminder ? $"Reminder: {TimeZoneInfo.ConvertTime(reminder, TimeZoneInfo.FindSystemTimeZoneById(entry.TimeZone)):yyyy-MM-dd HH:mm} {entry.TimeZone}." : "No reminder set.")
        : Status == "completed" && Data is null ? Message : JsonSerializer.Serialize(this);
    private CalendarEntry? EventData() => Data switch
    {
        CalendarEntry entry => entry,
        JsonElement { ValueKind: JsonValueKind.Object } element when element.TryGetProperty("Title", out _) => element.Deserialize<CalendarEntry>(),
        _ => null
    };
}
internal sealed class CalendarState
{
    public List<CalendarEntry> Entries { get; set; } = [];
    public List<CalendarProposal> Pending { get; set; } = [];
    public List<CalendarNotice> Notices { get; set; } = [];
}