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 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 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;
// The slide's OWN crop (phase 2, crop per use). All null = no override: the slide uses its photo's crop and set exactly
// as before. FocusX/FocusY/Zoom set = the slide has its own crop (the wide and tall overrides are optional on top).
public double? FocusX { get; set; }
public double? FocusY { get; set; }
public double? Zoom { get; set; }
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; }
/// The set cut for the slide's own crop; empty until it is complete (the photo's set stays live until then).
public string? SetHash { get; set; }
public List? Variants { get; set; }
/// True when the slide has a crop of its own.
public bool HasOwnCrop => FocusX is not null && FocusY is not null;
public void ClearOwnCrop()
{
(FocusX, FocusY, Zoom) = (null, null, null);
(WideFocusX, WideFocusY, WideZoom) = (null, null, null);
(TallFocusX, TallFocusY, TallZoom) = (null, null, null);
SetHash = null;
Variants = null;
}
}
/// 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; }
/// The file name as uploaded (for display only, cleaned; never used as a path). Null for photos uploaded before it was stored.
public string? OriginalFileName { get; set; }
/// The moment the photo was last detached from a slide; null while it was never used. The clean-up counts from here (decision 8).
public DateTimeOffset? LastUsedAt { get; set; }
/// Set when the photo was moved to the trash; its files stay for Media:TrashDays and it is hidden from the hero.
public DateTimeOffset? DeletedAt { 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,
};
}
///
/// The same photo as , always stored in HeroImages. Only used while the photos live in the
/// library (phase 3b): then HeroImages is kept up to date from the library rows so the switch can be turned back.
///
public class LegacyHeroImage
{
public Guid Id { get; set; }
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 string? OriginalFileName { get; set; }
public DateTimeOffset? LastUsedAt { get; set; }
public DateTimeOffset? DeletedAt { get; set; }
}
/// 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;
}