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

namespace e_suite.Modules.SiteManager.UnitTests.Helpers;

public class FakeSiteManagerRepository : FakeRepository, ISiteManagerRepository
{
    public List<Site> Sites { get; set; } = [];

    public Site EditedSite { get; private set; } = null!;

    public IQueryable<Site> GetSites()
    {
        return Sites.BuildMock();
    }

    public Task<Site?> GetSite(IGeneralIdRef generalIdRef, CancellationToken cancellationToken)
    {
        return Task.FromResult(GetSites().FindByGeneralIdRef(generalIdRef));
    }

    public Task<Site?> GetSite(long sigmaId, CancellationToken cancellationToken)
    {
        return Task.FromResult(GetSites().SingleOrDefault(x => x.SigmaId == sigmaId));
    }

    public Task EditSite(AuditUserDetails auditUserDetails, Site editedSite, CancellationToken cancellationToken)
    {
        EditedSite = editedSite;
        return Task.CompletedTask;
    }
    

    public Task CreateSite(AuditUserDetails auditUserDetails, Site newSite, CancellationToken cancellationToken)
    {
        Sites.Add(newSite);
        return Task.CompletedTask;
    }

    public Task CreateSite(AuditUserDetails auditUserDetails, IEnumerable<Site> newSites, CancellationToken cancellationToken)
    {
        Sites.AddRange(newSites);
        return Task.CompletedTask;
    }
}