using FruitBank.Common.Entities;
using LinqToDB;
using Mango.Nop.Data.Repositories;
using Nop.Core.Caching;
using Nop.Core.Configuration;
using Nop.Core.Events;
using Nop.Data;

namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;

public class StockTakingItemPalletDbTable : MgDbTableBase<StockTakingItemPallet>
{
    public StockTakingItemPalletDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings)
        : base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings)
    {
    }

    public override IQueryable<StockTakingItemPallet> GetAll() => base.GetAll();

    public IQueryable<StockTakingItemPallet> GetAll(bool loadRelations)
    {
        return loadRelations
            ? GetAll()
                .LoadWith(stip => stip.StockTakingItem).ThenLoad(sti => sti.StockTaking)
                .LoadWith(stip => stip.StockTakingItem).ThenLoad(sti => sti.Product).ThenLoad(prod => prod.GenericAttributes)
            : GetAll();
    }
}