using AyCode.Core.Serializers.Attributes;
using AyCode.Core.Serializers.Toons;
using LinqToDB.Mapping;
using Mango.Nop.Core.Entities;

namespace FruitBank.Common.Entities;

[AcBinarySerializable(false, true, false, true, false, false)]
[ToonDescription("Inventory session record", Purpose = "Orchestrates inventory sessions by freezing logical stock states")]
[Table(Name = FruitBankConstClient.StockTakingDbTableName)]
[System.ComponentModel.DataAnnotations.Schema.Table(FruitBankConstClient.StockTakingDbTableName)]
public sealed class StockTaking : MgStockTaking<StockTakingItem>
{
    public override bool IsReadyForClose()
    {
        if (StockTakingItems == null || StockTakingItems.Count == 0) return false;
        return StockTakingItems.Where(stockTakingItem => stockTakingItem is { IsRequiredForMeasuring: true, IsInvalid: false }).All(x => x.IsMeasured);
    }
}