using FruitBank.Common.Interfaces;
using Nop.Core.Domain.Orders;
using Nop.Plugin.Misc.FruitBankPlugin.Models.Orders;
using Nop.Services.Common;

namespace Nop.Plugin.Misc.FruitBankPlugin.Services
{
    public interface IOrderMeasurementService
    {
        Task<bool> IsPendingMeasurementAsync(Order order);
    }

    public class OrderMeasurementService : IOrderMeasurementService
    {
        private readonly IGenericAttributeService _genericAttributeService;

        public OrderMeasurementService(IGenericAttributeService genericAttributeService)
        {
            _genericAttributeService = genericAttributeService;
        }

        public async Task<bool> IsPendingMeasurementAsync(Order order)
        {
            if (order == null)
                return false;

            return await _genericAttributeService.GetAttributeAsync<bool>(
                order, nameof(IMeasurable.IsMeasurable), order.StoreId);
        }
    }
}
