using e_suite.API.Common.repository;
using e_suite.Database.Audit;
using e_suite.Database.Core.Extensions;
using e_suite.Database.Core.Tables.Domain;
using e_suite.UnitTestCore;
using eSuite.Core.Miscellaneous;
using MockQueryable;

namespace e_suite.Modules.DomainManager.UnitTests.Helpers;

public class FakeDomainRepository : FakeRepository, IDomainRepository
{
    public List<Domain> Domains = new();
    public Domain? AddAdministratorRoleCalled = null;
    public Domain? EditDomainCalled = null;


    public IQueryable<Domain> GetDomains()
    {
        return Domains.BuildMock();
    }

    public Task<Domain?> GetDomainById(IGeneralIdRef generalIdRef, CancellationToken cancellationToken)
    { 
        return Task.FromResult(GetDomains().FindByGeneralIdRef(generalIdRef));
    }

    public Task<Domain?> GetDomainByName(string domainName, CancellationToken cancellationToken)
    {
        return Task.FromResult(GetDomains().SingleOrDefault(x => x.Name == domainName));
    }

    public Task EditDomainAsync(AuditUserDetails auditUserDetails, Domain domain, CancellationToken cancellationToken)
    {
        EditDomainCalled = domain;
        return Task.CompletedTask;
    }

    public Task CreateDomainAsync(AuditUserDetails auditUserDetails, Domain domain, CancellationToken cancellationToken)
    {
        Domains.Add(domain);
        return Task.CompletedTask;
    }

    public Task AddAdministratorRoleAsync(AuditUserDetails auditUserDetails, Domain domain, CancellationToken cancellationToken)
    {
        AddAdministratorRoleCalled = domain;
        return Task.CompletedTask;
    }
}