using System.ComponentModel.DataAnnotations; using System.Text.Json.Serialization; using API.Schema.ActionsContext.Actions; using API.Schema.ActionsContext.Actions.Generic; // ReSharper disable UnusedAutoPropertyAccessor.Global namespace API.Controllers.DTOs; public sealed record ActionRecord : Identifiable { public ActionRecord(Schema.ActionsContext.ActionRecord actionRecord) : base(actionRecord.Key) { Action = actionRecord.Action; PerformedAt = actionRecord.PerformedAt; MangaId = actionRecord is IActionWithMangaRecord manga ? manga.MangaId : null; ChapterId = actionRecord is IActionWithChapterRecord chapter ? chapter.ChapterId : null; From = actionRecord is DataMovedActionRecord from ? from.From : null; To = actionRecord is DataMovedActionRecord to ? to.To : null; Filename = actionRecord is CoverDownloadedActionRecord filename ? filename.Filename : null; MetadataFetcher = actionRecord is MetadataUpdatedActionRecord metadata ? metadata.MetadataFetcher : null; } /// /// /// [Required] public ActionsEnum Action { get; init; } /// /// /// [Required] public DateTime PerformedAt { get; init; } /// /// MangaId if Record is /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? MangaId { get; init; } /// /// ChapterId if Record is /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? ChapterId { get; init; } /// /// FromPath if Record is /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? From { get; init; } /// /// ToPath if Record is /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? To { get; init; } /// /// Filename if Record is /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Filename { get; init; } /// /// if Record is /// [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? MetadataFetcher { get; init; } }