using SlpModularCms.Core.Media; namespace SlpModularCms.Modules.Hero.Data.Entities; /// The hero of the site in one language: texts, up to two buttons, the display, the schedule and the slides. public class HeroContent { public Guid Id { get; set; } /// Unique; only is exposed and edited now, the column keeps the model ready for more. public string Language { get; set; } = HeroLanguages.Default; public string Title { get; set; } = string.Empty; public string? Tagline { get; set; } public string? Lead { get; set; } public string Display { get; set; } = HeroDisplays.Single; public string? Button1Label { get; set; } public string? Button1Target { get; set; } public string? Button2Label { get; set; } public string? Button2Target { get; set; } public DateTimeOffset? StartsAt { get; set; } public DateTimeOffset? EndsAt { get; set; } public bool IsActive { get; set; } = true; public DateTimeOffset UpdatedAt { get; set; } public Guid LastModifiedByUserId { get; set; } public List Slides { get; set; } = []; } public class HeroSlide { public Guid Id { get; set; } public Guid HeroId { get; set; } public Guid ImageId { get; set; } public HeroImage? Image { get; set; } public string Alt { get; set; } = string.Empty; public bool Decorative { get; set; } public int SortOrder { get; set; } public bool IsActive { get; set; } = true; } /// A stored image: the original (never served), where the subject is, and the current set of variants. public class HeroImage { public Guid Id { get; set; } /// SHA-256 of the file as uploaded (hex); the same photo uploaded twice is one image. public string OriginalSha256 { get; set; } = string.Empty; public string OriginalKey { get; set; } = string.Empty; public string SourceFormat { get; set; } = string.Empty; public int Width { get; set; } public int Height { get; set; } public long Bytes { get; set; } public double FocusX { get; set; } = 0.5; public double FocusY { get; set; } = 0.5; public double Zoom { get; set; } = 1.0; public double? WideFocusX { get; set; } public double? WideFocusY { get; set; } public double? WideZoom { get; set; } public double? TallFocusX { get; set; } public double? TallFocusY { get; set; } public double? TallZoom { get; set; } public string SetHash { get; set; } = string.Empty; public List Variants { get; set; } = []; public DateTimeOffset CreatedAt { get; set; } public Guid CreatedByUserId { get; set; } public FocusSetting General => new FocusSetting(FocusX, FocusY, Zoom).Normalize(); public FocusSetting FocusFor(string ratio) => ratio switch { "wide" when WideFocusX is not null && WideFocusY is not null => new FocusSetting(WideFocusX.Value, WideFocusY.Value, WideZoom ?? Zoom).Normalize(), "tall" when TallFocusX is not null && TallFocusY is not null => new FocusSetting(TallFocusX.Value, TallFocusY.Value, TallZoom ?? Zoom).Normalize(), _ => General, }; } /// One file of the current set: the ratio, its pixel size, the type and the file name inside the set. public record HeroVariant(string Ratio, int Width, int Height, string Type, string FileName, long Bytes); /// A set or an original that nothing uses any more; the clean-up deletes it once the retention time has passed. public class HeroRetiredFile { public Guid Id { get; set; } /// set (a set hash) or original (an original key). public string Kind { get; set; } = string.Empty; public string Key { get; set; } = string.Empty; public DateTimeOffset RetiredAt { get; set; } } public static class HeroLanguages { public const string Default = "nl"; } public static class HeroDisplays { public const string Single = "single"; public const string Slideshow = "slideshow"; public static bool IsValid(string? value) => value is Single or Slideshow; }