Files
Wino-Mail/Wino.Core.Domain/Entities/Calendar/CalendarItem.cs

93 lines
2.2 KiB
C#
Raw Normal View History

using System;
using System.Diagnostics;
using Itenso.TimePeriod;
using SQLite;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Helpers;
using Wino.Core.Domain.Interfaces;
2025-02-16 11:54:23 +01:00
namespace Wino.Core.Domain.Entities.Calendar;
[DebuggerDisplay("{Title} ({StartDate} - {EndDate})")]
public class CalendarItem : ICalendarItem
{
2025-02-16 11:54:23 +01:00
[PrimaryKey]
public Guid Id { get; set; } = Guid.NewGuid();
[NotNull]
public string RemoteEventId { get; set; } = string.Empty;
[NotNull]
public Guid CalendarId { get; set; }
[Ignore]
public IAccountCalendar AssignedCalendar { get; set; }
[NotNull]
public string Title { get; set; } = string.Empty;
public string? Description { get; set; }
public string? Location { get; set; }
public string? HtmlLink { get; set; }
public DateTime StartDateTime { get; set; }
public DateTime EndDateTime { get; set; }
2025-02-16 11:54:23 +01:00
private ITimePeriod _period;
public ITimePeriod Period
{
get
{
_period ??= new TimeRange(StartDateTime, EndDateTime);
2025-02-16 11:54:23 +01:00
return _period;
}
2025-02-16 11:54:23 +01:00
}
public bool IsAllDay { get; set; }
public string? TimeZone { get; set; }
public string? RecurrenceRules { get; set; }
public string? Status { get; set; }
public string? OrganizerDisplayName { get; set; }
2025-02-16 11:54:23 +01:00
public string? OrganizerEmail { get; set; }
2025-02-16 11:54:23 +01:00
public DateTime CreatedDate { get; set; }
2025-02-16 11:54:23 +01:00
public DateTime LastModified { get; set; }
2025-02-16 11:54:23 +01:00
public bool IsDeleted { get; set; }
2025-02-16 11:54:23 +01:00
public string? RecurringEventId { get; set; }
2025-02-16 11:54:23 +01:00
public string? OriginalStartTime { get; set; }
2025-02-16 11:54:23 +01:00
/// <summary>
/// The type of calendar item (Timed, AllDay, MultiDay, etc.)
2025-02-16 11:54:23 +01:00
/// </summary>
2025-07-07 21:03:07 +02:00
public CalendarItemType ItemType { get; set; }
2025-02-16 11:54:23 +01:00
/// <summary>
/// Automatically determines and sets the ItemType based on event properties
2025-02-16 11:54:23 +01:00
/// </summary>
public void DetermineItemType()
2025-02-16 11:54:23 +01:00
{
var hasRecurrence = !string.IsNullOrEmpty(RecurrenceRules);
var isCancelled = Status?.ToLowerInvariant() == "cancelled" || IsDeleted;
ItemType = CalendarItemTypeHelper.DetermineItemType(
StartDateTime,
EndDateTime,
IsAllDay,
hasRecurrence,
isCancelled,
Status);
}
}