using Esiur.Data.Types;
using Esiur.Protocol;
using Esiur.Resource;
using Esiur.Security.Authority;
using Esiur.Security.Permissions;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Esiur.Security.Management;
///
/// Immutable metadata describing a resource operation being evaluated by managers.
/// is the sole mutable value and allows rate-control managers to
/// request deferred execution.
///
public sealed class ResourceManagerContext
{
readonly IReadOnlyList _memberPolicyAttributes;
public Warehouse Warehouse { get; }
public EpConnection? Connection { get; }
public Session? Session { get; }
public IResource? Resource { get; }
public MemberDef? Member { get; }
public ActionType Action { get; }
public object? Inquirer { get; }
///
/// Gets the local attributes that configure manager policy for the target member.
/// The collection is a defensive, read-only snapshot.
///
public IReadOnlyList MemberPolicyAttributes => _memberPolicyAttributes;
///
/// Gets or sets an optional delay requested by a rate-control manager.
///
public TimeSpan Delay { get; set; }
public ResourceManagerContext(
Warehouse warehouse,
EpConnection? connection,
Session? session,
IResource? resource,
MemberDef? member,
ActionType action,
object? inquirer = null,
IEnumerable? memberPolicyAttributes = null)
{
Warehouse = warehouse ?? throw new ArgumentNullException(nameof(warehouse));
Connection = connection;
Session = session;
Resource = resource;
Member = member;
Action = action;
Inquirer = inquirer;
var policies = memberPolicyAttributes?.ToArray() ?? Array.Empty();
if (policies.Any(attribute => attribute == null))
throw new ArgumentException(
"Member policy attributes cannot contain null values.",
nameof(memberPolicyAttributes));
_memberPolicyAttributes = Array.AsReadOnly(policies);
}
}