using System; using System.Collections.Generic; using System.Linq; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Querying; namespace MediaBrowser.Controller.Dto { /// /// Options that control which fields and images are populated when building a . /// public class DtoOptions { private static readonly ItemFields[] DefaultExcludedFields = [ ItemFields.SeasonUserData, ItemFields.RefreshState ]; private static readonly ImageType[] AllImageTypes = Enum.GetValues(); private static readonly ItemFields[] AllItemFields = Enum.GetValues() .Except(DefaultExcludedFields) .ToArray(); /// /// Initializes a new instance of the class with all fields enabled. /// public DtoOptions() : this(true) { } /// /// Initializes a new instance of the class. /// /// Whether to populate all available fields. public DtoOptions(bool allFields) { ImageTypeLimit = int.MaxValue; EnableImages = true; EnableUserData = true; AddCurrentProgram = true; Fields = allFields ? AllItemFields : []; ImageTypes = AllImageTypes; } /// /// Gets or sets the fields to populate on the DTO. /// public IReadOnlyList Fields { get; set; } /// /// Gets or sets the image types to populate on the DTO. /// public IReadOnlyList ImageTypes { get; set; } /// /// Gets or sets the maximum number of images to return per image type. /// public int ImageTypeLimit { get; set; } /// /// Gets or sets a value indicating whether image information is populated. /// public bool EnableImages { get; set; } /// /// Gets or sets a value indicating whether program recording information is populated. /// public bool AddProgramRecordingInfo { get; set; } /// /// Gets or sets a value indicating whether user data is populated. /// public bool EnableUserData { get; set; } /// /// Gets or sets a value indicating whether the currently airing program is populated. /// public bool AddCurrentProgram { get; set; } /// /// Gets or sets a value indicating whether an episode's portrait poster (its season's primary /// image, falling back to the series') should replace the episode's own (16:9) primary image. /// Used by views that render episodes as poster cards, e.g. "Latest". /// public bool PreferEpisodeParentPoster { get; set; } /// /// Gets a value indicating whether the specified field is populated. /// /// The field to check. /// true if the field is populated; otherwise, false. public bool ContainsField(ItemFields field) => Fields.Contains(field); /// /// Gets the number of images to return for the specified image type. /// /// The image type. /// The image limit for the type, or 0 if the type is not enabled. public int GetImageLimit(ImageType type) { if (EnableImages && ImageTypes.Contains(type)) { return ImageTypeLimit; } return 0; } } }