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.SpecificationManager.UnitTests.Helpers;

public class FakeSpecificationManagerRepository : FakeRepository, ISpecificationManagerRepository
{
    public List<Specification> Specifications { get; set; } = [];
    public Specification? EditedSpecification { get; private set; }

    public IQueryable<Specification> GetSpecifications()
    {
        return Specifications.BuildMock();
    }

    public IQueryable<Specification> GetSpecificationsFromForms(IEnumerable<long> formIds)
    {
        throw new NotImplementedException();
    }

    public Task<Specification?> GetSpecification(GeneralIdRef generalIdRef, CancellationToken cancellationToken)
    {
        return Task.FromResult(GetSpecifications().FindByGeneralIdRef(generalIdRef));
    }

    public Task CreateSpecification(
        AuditUserDetails auditUserDetails,
        Specification newSpecification,
        CancellationToken cancellationToken
    )
    {
        Specifications.Add(newSpecification);
        return Task.CompletedTask;
    }

    public Task EditSpecification(
        AuditUserDetails auditUserDetails,
        Specification specification,
        CancellationToken cancellationToken
    )
    {
        EditedSpecification = specification;
        return Task.CompletedTask;
    }

    public Task CreateSpecification(AuditUserDetails auditUserDetails, IEnumerable<Specification> newSpecification, CancellationToken cancellationToken)
    {
        Specifications.AddRange(newSpecification);
        return Task.CompletedTask;
    }

    public async Task EditSpecification(AuditUserDetails auditUserDetails, IEnumerable<Specification> specifications, CancellationToken cancellationToken)
    {
        foreach (var specification in specifications)
        {
            await EditSpecification( auditUserDetails, specification, cancellationToken );
        }
    }
}