using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

using AIRuntime.Runtime.Models;
using AIRuntime.Runtime.Providers.Models;


namespace AIRuntime.Runtime.Providers.Testing
{
    /// <summary>
    /// Fake provider used to test the complete
    /// AI -> Tool -> Result -> Final Response loop.
    /// </summary>
    public sealed class FakeProvider : IProvider
    {
        private int _callCount;


        public string Name => "FakeProvider";



        public Task<ChatCompletion> ChatAsync(
            IReadOnlyList<ConversationMessage> messages,
            IReadOnlyList<ProviderTool> tools,
            CancellationToken cancellationToken)
        {
            _callCount++;


            //--------------------------------------------------
            // First response:
            // Pretend the AI requested a tool
            //--------------------------------------------------

            if (_callCount == 1)
            {
                ChatCompletion completion =
                    new ChatCompletion();


                completion.ToolCalls.Add(
                    new ToolCall
                    {
                        Id = "fake-call-001",

                        Name = "read_file",

                        Arguments =
                            @"{
    ""path"": ""test.txt""
}"
                    });


                return Task.FromResult(
                    completion);
            }



            //--------------------------------------------------
            // Second response:
            // Pretend AI received tool result
            //--------------------------------------------------

            return Task.FromResult(
                new ChatCompletion
                {
                    Content =
                        "FakeProvider successfully read the file."
                });
        }
    }
}