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

namespace SequenceManager.UnitTests.Repository;

public class FakeSequenceManagerRepository : FakeRepository, ISequenceManagerRepository
{
    public List<Sequence> Sequences = [];
    
    public Task AddSequence(AuditUserDetails auditUserDetails, Sequence sequence, CancellationToken cancellationToken)
    {
        Sequences.Add(sequence);
        return Task.CompletedTask;
    }

    public Task EditSequence(AuditUserDetails auditUserDetails, Sequence sequence, CancellationToken cancellationToken)
    {
        return Task.CompletedTask;
    }

    public async Task<Sequence?> GetSequenceById(IGeneralIdRef generalIdRef, CancellationToken cancellationToken)
    {
        var sequence = Sequences.AsQueryable().FindByGeneralIdRef(generalIdRef);
        return await Task.FromResult(sequence);
    }

    public async Task<Sequence?> GetSequenceByName(string Name, CancellationToken cancellationToken)
    {
        return await Task.FromResult(Sequences.Where(x => x.Name == Name).FirstOrDefault());
    }

    public IQueryable<Sequence> GetSequenceList()
    {
        var sequences = Sequences.Where(x => !x.Deleted).ToList().BuildMock();
        return sequences;
    }
}