using System;
using MediaBrowser.Model.Services;
namespace MediaBrowser.Controller.Net
{
    public class AuthenticatedAttribute : Attribute, IHasRequestFilter, IAuthenticationAttributes
    {
        public static IAuthService AuthService { get; set; }
        /// 
        /// Gets or sets the roles.
        /// 
        /// The roles.
        public string Roles { get; set; }
        /// 
        /// Gets or sets a value indicating whether [escape parental control].
        /// 
        /// true if [escape parental control]; otherwise, false.
        public bool EscapeParentalControl { get; set; }
        /// 
        /// Gets or sets a value indicating whether [allow before startup wizard].
        /// 
        /// true if [allow before startup wizard]; otherwise, false.
        public bool AllowBeforeStartupWizard { get; set; }
        public bool AllowLocal { get; set; }
        /// 
        /// The request filter is executed before the service.
        /// 
        /// The http request wrapper
        /// The http response wrapper
        /// The request DTO
        public void RequestFilter(IRequest request, IResponse response, object requestDto)
        {
            AuthService.Authenticate(request, this);
        }
        /// 
        /// Order in which Request Filters are executed.
        /// <0 Executed before global request filters
        /// >0 Executed after global request filters
        /// 
        /// The priority.
        public int Priority
        {
            get { return 0; }
        }
        public string[] GetRoles()
        {
            return (Roles ?? string.Empty).Split(new []{ ',' }, StringSplitOptions.RemoveEmptyEntries);
        }
    }
    public interface IAuthenticationAttributes
    {
        bool EscapeParentalControl { get; }
        bool AllowBeforeStartupWizard { get; }
        bool AllowLocal { get; }
        string[] GetRoles();
    }
}