using System.Net;
using IWS5.Autotest.IWS5.Api.Api;
using IWS5.Autotest.IWS5.Api.Common;
using IWS5.Core.Models.Request;

namespace IWS5.Autotest.IWS5.Autotests
{
    [TestFixture]
    public class WorkItemTests
    {
        private SessionApi _sessionApi;
        private WorkItemControllerApi _workItemApi;        

        public WorkItemTests()
        {
            _sessionApi = new SessionApi();
            _workItemApi = new WorkItemControllerApi(_sessionApi.SessionStorage);
        }

        [OneTimeSetUp]
        public async Task Init()
        {
            await _sessionApi.SignIn();
        }

        [Test]
        public async Task Create_And_Forward_WorkItem_ReturnsSuccess()
        {
            //Arrange 
            var createRequest = new CreateWorkItemRequest
            {
                WorkItemName = "Autotest WorkItem",
                ProcessId = 105, // EmarK
                FolderFields = [],
                Documents = [],
                Notes = []
            };

            //Act
            var createResponse = await _workItemApi.CreateWorkItem(createRequest);
            var data = createResponse.Data!; 

            var createdWorkItem = createResponse.Data!;

            //GET/ api / Queue /{ processId}            Retrieves a list of queues for a specific process. 
            /*     {  "processId": 105,  "processName": "Emark",  "queues": [  {   "queueId": 28,    "queueName": "Staff Review Queue",}
                          actionFromDropDown: "approved" relatedQueueId: 28 workItemReferenceId: */

            // Arrange
            var forwardRequest = new ForwardWorkItemRequest
            {
                WorkItemReferenceId = createdWorkItem.ResponseModel.WorkItemReferenceId,
                ActionFromDropDown = "approved",   
                RelatedQueueId = 28                
            };

            var forwardResponse = await _workItemApi.ForwardWorkItem(forwardRequest);

            Assert.Multiple(() =>
            {
                Assert.That(createResponse.StatusCode, Is.EqualTo(HttpStatusCode.OK));
                Assert.That(createResponse.Data, Is.Not.Null);
                Assert.That(forwardResponse.StatusCode, Is.EqualTo(HttpStatusCode.OK));
                Assert.That(forwardResponse.Data, Is.Not.Null);
            });
        }
    }
}