using System.Security.Claims;
using e_suite.API.Common;
using e_suite.Service.Sentinel;
using e_suite.UnitTestCore;
using eSuite.API.Controllers;
using eSuite.API.SingleSignOn;
using eSuite.API.Translation;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Moq;

namespace eSuite.API.UnitTests.Controllers.AccountControllerUnitTests;

public abstract class AccountControllerTestBase : TestBase
{
    protected AccountController _accountController = null!;
    protected Mock<IUserManager> _userManagerMock = null!;
    protected Mock<ISentinel> _sentinelMock = null!;
    protected Mock<ISingleSignOn> _singleSignOnMock = null!;
    protected Mock<ICookieManager> _cookieManagerMock = null!;
    protected Mock<ITranslatorFactory> _translatorFactoryMock = null!;
    protected Mock<ITranslator> _translatorMock = null!;

    public override async Task Setup()
    {
        await base.Setup();

        _userManagerMock = new Mock<IUserManager>();
        _sentinelMock = new Mock<ISentinel>();
        _singleSignOnMock = new Mock<ISingleSignOn>();
        _cookieManagerMock = new Mock<ICookieManager>();

        _translatorMock = new Mock<ITranslator>();
        _translatorFactoryMock = new Mock<ITranslatorFactory>();
        _translatorFactoryMock.Setup(x => x.Use(It.IsAny<Namespaces>())).ReturnsAsync(_translatorMock.Object);

        _accountController = new AccountController(_userManagerMock.Object,_sentinelMock.Object, _singleSignOnMock.Object, _cookieManagerMock.Object, _translatorFactoryMock.Object);
    }

    protected void AddAuthorisedUserToController(long id, string email, string displayName)
    {
        var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
        {
            new(ClaimTypes.PrimarySid, id.ToString()),
            new(ClaimTypes.Email, email),
            new(ClaimTypes.Name, displayName)
            // other required and custom claims
        }, "TestAuthentication"));

        _accountController.ControllerContext = new ControllerContext
        {
            HttpContext = new DefaultHttpContext { User = user }
        };
    }

}