using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Jellyfin.Database.Implementations.Entities;
using Jellyfin.Plugin.WatchedTogether.Configuration;
namespace Jellyfin.Plugin.WatchedTogether.Services;
///
/// Computes, applies and checks the content restrictions a shared account should have.
///
public interface IRestrictionService
{
///
/// Computes the strictest combination of the given members' restrictions.
///
/// The members to combine.
/// Restrictions at least as strict as every member's.
ContentRestrictions ComputeStrictest(IReadOnlyList memberIds);
///
/// Finds the range the members' parental rating caps span.
///
/// The members to inspect.
/// The strictest and loosest caps among them.
RatingRange GetRatingRange(IReadOnlyList memberIds);
///
/// Writes the restrictions a group's shared account should have: the strictest member's,
/// except for the rating cap when the group has chosen its own.
///
/// The group whose shared account to update.
///
/// The restrictions written, and whether the group's chosen cap had to be adjusted to stay
/// within its members' range - in which case has been updated in
/// place and the caller should persist it.
///
Task ApplyAsync(SharedGroup group);
///
/// Determines whether hides at least everything
/// cannot see, reading both users live.
///
/// The shared account being unlocked.
/// The member whose password matched.
/// true if the member may unlock the account.
bool IsAtLeastAsStrict(User candidate, User member);
}
///
/// The range spanned by a set of members' parental rating caps.
///
/// The lowest cap, or null if no member has one.
/// The highest cap, or null if any member has none.
public readonly record struct RatingRange(int? Strictest, int? Loosest)
{
///
/// Gets a value indicating whether there is anything to choose: at least one member is capped.
///
public bool HasChoice => Strictest is not null;
}
///
/// The outcome of applying a group's restrictions to its shared account.
///
/// What was written.
/// Whether the group's chosen cap was changed to fit its members' range.
public sealed record RestrictionApplyResult(ContentRestrictions Restrictions, bool CapAdjusted);