using System.Security.Claims;
using e_suite.Messaging.Common;
using e_suite.UnitTestCore;
using eSuite.API.Controllers;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Moq;

namespace eSuite.API.UnitTests.Controllers.InternalMessagingControllerUnitTests;

public abstract class InternalMessagingControllerTestBase : TestBase
{
    protected Mock<ISigmaImportMessageSender> _sigmaImportMessageSenderMock = null!;
    protected Mock<IDatabaseMessageSender> _databaseMessageSenderMock = null!;
    protected Mock<IEFlowSyncMessageSender> _eFlowSyncMessageSenderMock = null!;
    protected Mock<IActivityMessageSender> _activityMessageSenderMock = null!;
    protected InternalMessagingController _internalMessagingController = null!;

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

        _sigmaImportMessageSenderMock = new Mock<ISigmaImportMessageSender>();
        _databaseMessageSenderMock = new Mock<IDatabaseMessageSender>();
        _eFlowSyncMessageSenderMock = new Mock<IEFlowSyncMessageSender>();
        _activityMessageSenderMock = new Mock<IActivityMessageSender>();

        _internalMessagingController =
            new InternalMessagingController(_sigmaImportMessageSenderMock.Object, _databaseMessageSenderMock.Object, _eFlowSyncMessageSenderMock.Object, _activityMessageSenderMock.Object);

        const long id = -1;
        const string email = "email@mail.test";
        const string displayName = "Testy McTester";

        AddAuthorisedUserToController(id, email, displayName);
    }

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

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