using Newtonsoft.Json;
using System;
using System.Collections.ObjectModel;
using System.Linq;

namespace MasterDevs.ChromeDevTools.ProtocolGenerator
{
    public class Domain : ProtocolItem
    {
        public Domain()
        {
            this.Types = new Collection<Type>();
            this.Events = new Collection<Event>();
            this.Commands = new Collection<Command>();
        }

        [JsonProperty(PropertyName = "domain")]
        public override string Name
        {
            get;
            set;
        }

        public Collection<Type> Types
        {
            get;
            set;
        }

        public Collection<Command> Commands
        {
            get;
            set;
        }

        public Collection<Event> Events
        {
            get;
            set;
        }

        public string Availability
        {
            get;
            set;
        }

        public string FeatureGuard
        {
            get;
            set;
        }

        public Command GetCommand(string name)
        {
            return this.Commands.SingleOrDefault(c => string.Equals(c.Name, name, StringComparison.OrdinalIgnoreCase));
        }

        public Type GetType(string name)
        {
            return this.Types.SingleOrDefault(t => string.Equals(t.Name, name, StringComparison.OrdinalIgnoreCase));
        }
    }
}