using System.Collections.Generic;

using AIRuntime.Runtime.Agents;
using AIRuntime.Runtime.Agents.BuiltIn;

using NUnit.Framework;


namespace AIRuntime.Tests
{
    public sealed class BuiltInAgentTests
    {
        //--------------------------------------------------
        // Identity Tests
        //--------------------------------------------------

        [Test]
        public void ArchitectAgent_HasCorrectIdentity()
        {
            AgentDefinition agent =
                ArchitectAgentDefinition.Create();


            Assert.AreEqual(
                "ArchitectAgent",
                agent.Id);


            Assert.AreEqual(
                "Architect Agent",
                agent.DisplayName);


            Assert.IsFalse(
                string.IsNullOrWhiteSpace(
                    agent.Description));


            Assert.IsFalse(
                string.IsNullOrWhiteSpace(
                    agent.SystemPrompt));
        }



        [Test]
        public void DeveloperAgent_HasCorrectIdentity()
        {
            AgentDefinition agent =
                DeveloperAgentDefinition.Create();


            Assert.AreEqual(
                "DeveloperAgent",
                agent.Id);


            Assert.AreEqual(
                "Developer Agent",
                agent.DisplayName);


            Assert.IsFalse(
                string.IsNullOrWhiteSpace(
                    agent.Description));


            Assert.IsFalse(
                string.IsNullOrWhiteSpace(
                    agent.SystemPrompt));
        }



        [Test]
        public void TestingAgent_HasCorrectIdentity()
        {
            AgentDefinition agent =
                TestingAgentDefinition.Create();


            Assert.AreEqual(
                "TestingAgent",
                agent.Id);


            Assert.AreEqual(
                "Testing Agent",
                agent.DisplayName);


            Assert.IsFalse(
                string.IsNullOrWhiteSpace(
                    agent.Description));


            Assert.IsFalse(
                string.IsNullOrWhiteSpace(
                    agent.SystemPrompt));
        }



        [Test]
        public void ReviewAgent_HasCorrectIdentity()
        {
            AgentDefinition agent =
                ReviewAgentDefinition.Create();


            Assert.AreEqual(
                "ReviewAgent",
                agent.Id);


            Assert.AreEqual(
                "Review Agent",
                agent.DisplayName);


            Assert.IsFalse(
                string.IsNullOrWhiteSpace(
                    agent.Description));


            Assert.IsFalse(
                string.IsNullOrWhiteSpace(
                    agent.SystemPrompt));
        }



        //--------------------------------------------------
        // Registry Integration
        //--------------------------------------------------

        [Test]
        public void BuiltInAgents_CanRegister()
        {
            AgentRegistry registry =
                new AgentRegistry();


            List<AgentDefinition> agents =
                new List<AgentDefinition>
                {
                    ArchitectAgentDefinition.Create(),

                    DeveloperAgentDefinition.Create(),

                    TestingAgentDefinition.Create(),

                    ReviewAgentDefinition.Create()
                };


            foreach (AgentDefinition agent in agents)
            {
                registry.Register(
                    agent);
            }


            Assert.AreEqual(
                4,
                registry.Count);


            Assert.IsTrue(
                registry.Contains(
                    "ArchitectAgent"));


            Assert.IsTrue(
                registry.Contains(
                    "DeveloperAgent"));


            Assert.IsTrue(
                registry.Contains(
                    "TestingAgent"));


            Assert.IsTrue(
                registry.Contains(
                    "ReviewAgent"));
        }



        //--------------------------------------------------
        // Definition Validation
        //--------------------------------------------------

        [Test]
        public void BuiltInAgents_HaveUniqueIds()
        {
            HashSet<string> ids =
                new HashSet<string>();


            AgentDefinition[] agents =
            {
                ArchitectAgentDefinition.Create(),

                DeveloperAgentDefinition.Create(),

                TestingAgentDefinition.Create(),

                ReviewAgentDefinition.Create()
            };


            foreach (AgentDefinition agent in agents)
            {
                Assert.IsTrue(
                    ids.Add(
                        agent.Id),
                    "Duplicate agent id found: " + agent.Id);
            }
        }
    }
}