using IWS5.Autotest.IWS5.Api.Api;
using IWS5.Autotest.IWS5.Helpers;
using IWS5.Core.Models.Request;

namespace IWS5.Autotest.IWS5.Autotests
{
    public class LogInTest
    {
        private readonly AuthenticationControllerApi _sessionApi = new();

        [Test]
        public async Task Post_LogIn_ReturnSuccess()
        {
            //Act
            var response = await _sessionApi.LoginUser(
                new LogInCredentials
                {
                    UserName = CredentialHelper.UserName,
                    Password = CredentialHelper.UserPassword
                }); ;

            //Assert
            Assert.Multiple(() =>
            {
                Assert.That(response.IsSuccessStatusCode, Is.True, "because the HTTP response should be successful or the user does not exist");
                Assert.That(response.Content, Is.Not.Null.And.Not.Empty, "Response content should not be empty");
            });
        }

        [Test]
        public async Task Post_LogIn_WithInvalidCredentials_ReturnsUnauthorized()
        {
            // Act
            var response = await _sessionApi.LoginUser(
                new LogInCredentials
                {
                    UserName = "invalidUser",  
                    Password = "invalidPassword"
                });

            // Assert
            Assert.Multiple(() =>
            {
                Assert.That(response.IsSuccessStatusCode, Is.False, "because login with invalid credentials should not be successful");
                Assert.That((int)response.StatusCode, Is.EqualTo(401), "because the API should return 401 Unauthorized for invalid credentials");
            });
        }
    }
}