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

namespace eSuite.API.UnitTests.Controllers.FormsControllerUnitTests;

public abstract class FormsControllerTestBase : TestBase
{
    protected FormsController _formsController = null!;
    protected Mock<IFormsManager>? _formsManagerMock;

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

    protected const string BadRequestText = "Bad request";
    protected const string NotFoundText = "Not found";

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

        _formsManagerMock = new Mock<IFormsManager>();

        _formsController = new FormsController(_formsManagerMock.Object);
        AddAuthorisedUserToController(id, email, displayName);
    }

    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"));

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