using IWS5.Autotest.IWS5.Api.Api;
using IWS5.Core.DTO;
using System.Net;
using IWS5.Autotest.IWS5.Api.Common;
using IWS5.Autotest.IWS5.Api.Common.Pashn.Autotests.Pashn.Api.Common;

namespace IWS5.Autotest.IWS5.Autotests
{
    public class InboxApiTests
    {
        private readonly WorkItemControllerApi _inboxApi;
        private readonly SessionApi _sessionApi;

        public InboxApiTests()
        {
            _sessionApi = new SessionApi();
            _inboxApi = new WorkItemControllerApi(_sessionApi.SessionStorage);
        }

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

        [Test]
        public async Task Get_WorkItemsInboxForUser_ReturnsSuccess()
        {
            var response = await _inboxApi.GetWorkItemsInboxForUser();

            Assert.Multiple(() =>
            {
                Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
                Assert.That(response.Data, Is.Null);
            });
        }

        //todo add check whe Ibox is present in a Process

        [Test]
        public async Task Get_WorkItemsForUser_Unauthorized_Returns401()
        {
            var sessionApi = new SessionApi();
            var fakeSession = new SessionStorage
            {
                token = sessionApi.GetWrongBearerToken()
            };

            var unauthorizedApi = new WorkItemControllerApi(fakeSession);

            var response = await unauthorizedApi.GetWorkItemsInboxForUser();

            Assert.Multiple(() =>
            {
                Assert.That((int)response.StatusCode, Is.EqualTo(401));
                Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
                Assert.That(response.Data, Is.Null);
            });
        }
    }
}