using System;
using System.Collections.Generic;


namespace AIRuntime.Runtime.Agents.Permissions
{
    /// <summary>
    /// Controls which capabilities an agent may access.
    /// </summary>
    public sealed class CapabilityAccessPolicy
    {
        private readonly HashSet<string> _allowed =
            new HashSet<string>();


        public IReadOnlyCollection<string> AllowedCapabilities
        {
            get
            {
                return _allowed;
            }
        }


        public void Allow(
            string capabilityName)
        {
            if (string.IsNullOrWhiteSpace(capabilityName))
            {
                throw new ArgumentException(
                    "Capability name cannot be empty.",
                    nameof(capabilityName));
            }


            _allowed.Add(
                capabilityName);
        }


        public void Deny(
            string capabilityName)
        {
            if (string.IsNullOrWhiteSpace(capabilityName))
            {
                return;
            }


            _allowed.Remove(
                capabilityName);
        }


        public bool CanUse(
            string capabilityName)
        {
            return _allowed.Contains(
                capabilityName);
        }


        public void Clear()
        {
            _allowed.Clear();
        }
    }
}