using e_suite.API.Common;
using e_suite.API.Common.repository;
using e_suite.Database.Audit;
using e_suite.UnitTestCore;

namespace e_suite.Modules.CustomFieldManagerUnitTests;

public class CustomFieldsTestBase<T> : TestBase
{
    protected Mock<ICustomFieldRepository> _customFieldRepository = null!;
    protected CustomFieldManager _customFieldManager = null!;
    protected FakeCustomFieldRepository _fakeCustomFieldRepository = null!;
    protected AuditUserDetails auditResult = null!;
    protected Mock<ICustomFieldReferenceObjectRepository> _customFieldReferenceObjectRepository = null!;
    protected FakeCustomFieldReferenceRepository _fakeCustomFieldReferenceRepository = null!;
    protected ICustomFieldHelper _customFieldHelper = null!;
    protected Mock<IPatchFactory> PatchFactoryMock = null!;
    protected Mock<IPatch<T>> PatchMock = null!;

    public override async Task Setup()
    {
        await base.Setup();
        auditResult = new AuditUserDetails
        {
            UserId = -1,
            UserDisplayName = "Testing User",
            Comment = "Test comment"
        };
        _customFieldRepository = new Mock<ICustomFieldRepository>();
        _fakeCustomFieldRepository = new FakeCustomFieldRepository();
        _customFieldReferenceObjectRepository = new Mock<ICustomFieldReferenceObjectRepository>();
        _fakeCustomFieldReferenceRepository = new FakeCustomFieldReferenceRepository();
        _customFieldHelper = new CustomFieldHelper(_fakeCustomFieldReferenceRepository);

        PatchFactoryMock = new Mock<IPatchFactory>();
        PatchMock = new Mock<IPatch<T>>();
        PatchFactoryMock
            .Setup(f => f.Create(It.IsAny<T>()))
            .Returns(PatchMock.Object);

        _customFieldManager = new CustomFieldManager(_fakeCustomFieldRepository, _fakeCustomFieldReferenceRepository, _customFieldHelper, PatchFactoryMock.Object);
    }
}