using System.ComponentModel.DataAnnotations; using SlpModularCms.Core.Media; using SlpModularCms.Core.Texts; namespace SlpModularCms.Modules.Hero; /// The keys of the Hero module texts (Texts/nl.json, Texts/en.json, key path hero.*). public static class HeroTexts { public static class Validation { public static class Title { public static readonly TextKey Required = new("hero.validation.title.required"); public static readonly TextKey TooLong = new("hero.validation.title.tooLong", "max"); public static readonly TextKey TooManyLines = new("hero.validation.title.tooManyLines", "max"); } public static readonly TextKey TaglineTooLong = new("hero.validation.tagline.tooLong", "max"); public static readonly TextKey LeadTooLong = new("hero.validation.lead.tooLong", "max"); public static readonly TextKey DisplayInvalid = new("hero.validation.display.invalid"); public static class Button { public static readonly TextKey Incomplete = new("hero.validation.button.incomplete"); public static readonly TextKey LabelTooLong = new("hero.validation.button.labelTooLong", "max"); public static readonly TextKey TargetTooLong = new("hero.validation.button.targetTooLong", "max"); public static readonly TextKey TargetInvalid = new("hero.validation.button.targetInvalid"); public static readonly TextKey TooMany = new("hero.validation.button.tooMany", "max"); } public static readonly TextKey EndAfterStart = new("hero.validation.schedule.endAfterStart"); public static class Slide { public static readonly TextKey ImageRequired = new("hero.validation.slide.imageRequired"); public static readonly TextKey ImageUnknown = new("hero.validation.slide.imageUnknown"); public static readonly TextKey AltRequired = new("hero.validation.slide.altRequired"); public static readonly TextKey AltTooLong = new("hero.validation.slide.altTooLong", "max"); public static readonly TextKey IdUnknown = new("hero.validation.slide.idUnknown"); } public static readonly TextKey FocusInvalid = new("hero.validation.focus.invalid", "maxZoom"); } public static class Image { public static readonly TextKey InUse = new("hero.image.inUse"); public static readonly TextKey NotFound = new("hero.image.notFound"); public static readonly TextKey StorageFull = new("hero.image.storageFull"); public static readonly TextKey TooLarge = new("hero.image.rejected.tooLarge", "max"); public static readonly TextKey UnsupportedFormat = new("hero.image.rejected.unsupportedFormat"); public static readonly TextKey Corrupt = new("hero.image.rejected.corrupt"); public static readonly TextKey TooManyPixels = new("hero.image.rejected.tooManyPixels"); public static readonly TextKey Timeout = new("hero.image.rejected.timeout"); public static readonly TextKey Busy = new("hero.image.rejected.busy"); public static readonly TextKey Unavailable = new("hero.image.rejected.unavailable"); /// The text key for a rejection; the size limit is given in MB for the "too large" message. public static TextKey For(ImageRejection reason) => reason switch { ImageRejection.TooLarge => TooLarge, ImageRejection.UnsupportedFormat => UnsupportedFormat, ImageRejection.Corrupt => Corrupt, ImageRejection.TooManyPixels => TooManyPixels, ImageRejection.Timeout => Timeout, ImageRejection.Busy => Busy, _ => Unavailable, }; } /// The catalogue of the request being validated, or the shared default one outside a request (unit tests). public static ITextCatalog From(ValidationContext? context) => context?.GetService(typeof(ITextCatalog)) as ITextCatalog ?? TextCatalog.Default; }