//using FruitBank.Common.Entities;
//using Nop.Core;
//using Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Models;
//using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
//using Nop.Web.Areas.Admin.Models.Orders;
//using Nop.Web.Framework.Models;
//using Nop.Web.Framework.Models.Extensions;

//namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Factories
//{
    
//    /// <summary>
//    /// Represents the shipment model factory implementation
//    /// </summary>
//    public partial class ShippingModelFactory : IFruitBankShippingModelFactory
//    {
//        #region Fields

//        // TODO: Add your services here
//        // private readonly IShippingService _shippingService;
//        // private readonly IPartnerService _partnerService;
//        // private readonly IDocumentService _documentService;
//        private readonly ShippingDbTable shippingDbTable;
//        #endregion

//        #region Ctor

//        public ShippingModelFactory(
//            // TODO: Add your service dependencies
//            )
//        {
//            // TODO: Initialize services
//        }

//        #endregion

//        #region Methods

//        /// <summary>
//        /// Prepare shipment search model
//        /// </summary>
//        /// <param name="searchModel">Shipment search model</param>
//        /// <returns>Shipment search model</returns>
//        public virtual Task<ShippingSearchModel> PrepareShippingSearchModelAsync(ShippingSearchModel searchModel)
//        {
//            ArgumentNullException.ThrowIfNull(searchModel);

//            // Set default values
//            // TODO: Add any additional search model preparation here
//            // For example, populate partner dropdown lists, etc.
//            searchModel.SetGridPageSize();
//            searchModel.Start = 1;
//            searchModel.Length = 10;
//            searchModel.SearchIsAllMeasured = 0; // All
//            searchModel.SearchLicencePlate = string.Empty;
//            searchModel.SearchPartnerId = 0;
//            searchModel.SearchShippingDateFrom = null;
//            searchModel.SearchShippingDateTo = null;


//            return Task.FromResult(searchModel);
//        }

//        /// <summary>
//        /// Prepare paged shipment list model
//        /// </summary>
//        /// <param name="searchModel">Shipment search model</param>
//        /// <returns>Shipment list model</returns>
//        public virtual async Task<ShippingListModel> PrepareShippingListModelAsync(ShippingSearchModel searchModel)
//        {
//            ArgumentNullException.ThrowIfNull(searchModel);

//            // TODO: Get shipments from your service
//            // var shipments = await _shippingService.GetShipmentsAsync(
//            //     dateFrom: searchModel.SearchShipmentDateFrom,
//            //     dateTo: searchModel.SearchShipmentDateTo,
//            //     licencePlate: searchModel.SearchLicencePlate,
//            //     partnerId: searchModel.SearchPartnerId > 0 ? searchModel.SearchPartnerId : null,
//            //     isAllMeasured: searchModel.SearchIsAllMeasured == 1 ? true : 
//            //                   searchModel.SearchIsAllMeasured == 2 ? false : null,
//            //     pageIndex: searchModel.Page - 1,
//            //     pageSize: searchModel.PageSize
//            // );

//            // Mock data for now - replace with actual service call
//            var shipments = shippingDbTable.GetAll().ToList();

//            // Prepare list model
//            var model = await ModelExtensions.PrepareToGridAsync<ShippingListModel, ShippingModel, Shipping>(
//                    new ShippingListModel(),
//                    searchModel,
//                    shipments.ToPagedList(searchModel),
//                    () => shipments.SelectAwait(async shipment => new ShippingModel
//                    {
//                        Id = shipment.Id,
//                        PartnerId = shipment.PartnerId,
//                        ShippingDate = shipment.ShippingDate,
//                        LicencePlate = shipment.LicencePlate,
//                        IsAllMeasured = shipment.IsAllMeasured,
//                        DocumentCount = shipment.ShippingDocuments?.Count ?? 0,
//                        Created = shipment.Created,
//                        Modified = shipment.Modified
//                    })
//                );

//            return model;
//        }

//        /// <summary>
//        /// Prepare shipment model
//        /// </summary>
//        /// <param name="model">Shipment model</param>
//        /// <param name="shipment">Shipment</param>
//        /// <returns>Shipment model</returns>
//        public virtual async Task<ShippingModel> PrepareShippingModelAsync(ShippingModel model, Shipping shipment)
//        {
//            if (shipment != null)
//            {
//                // Fill the model properties if the model is null
//                model ??= new ShippingModel
//                {
//                    Id = shipment.Id,
//                    PartnerId = shipment.PartnerId,
//                    ShippingDate = shipment.ShippingDate,
//                    LicencePlate = shipment.LicencePlate,
//                    IsAllMeasured = shipment.IsAllMeasured,
//                    Created = shipment.Created,
//                    Modified = shipment.Modified
//                };

//                // TODO: Get partner name from your service
//                // model.PartnerName = await _partnerService.GetPartnerNameAsync(shipment.PartnerId);
//                model.PartnerName = $"Partner {shipment.PartnerId}"; // Mock for now

//                // TODO: Get document count from your service
//                // model.DocumentCount = await _documentService.GetDocumentCountByShipmentIdAsync(shipment.Id);
//                model.DocumentCount = shipment.ShippingDocuments?.Count ?? 0;
//            }

//            return model;
//        }

//        #endregion

//        #region Utilities

//        // Mock data method - remove when you have real services
//        private async Task<IPagedList<Shipping>> GetMockShipmentsAsync(ShippingSearchModel searchModel)
//        {
//            await Task.Delay(1); // Simulate async operation

//            var mockData = new List<Shipping>();

//            for (int i = 1; i <= 50; i++)
//            {
//                mockData.Add(new Shipping
//                {
//                    Id = i,
//                    PartnerId = (i % 5) + 1,
//                    ShippingDate = DateTime.Now.AddDays(-i),
//                    LicencePlate = $"ABC-{i:D3}",
//                    IsAllMeasured = i % 3 == 0,
//                    Created = DateTime.Now.AddDays(-i),
//                    Modified = DateTime.Now.AddDays(-i / 2),
//                    ShippingDocuments = new List<ShippingDocument>()
//                });
//            }

//            // Apply search filters
//            if (searchModel.SearchShippingDateFrom.HasValue)
//                mockData = mockData.Where(s => s.ShippingDate >= searchModel.SearchShippingDateFrom.Value).ToList();

//            if (searchModel.SearchShippingDateTo.HasValue)
//                mockData = mockData.Where(s => s.ShippingDate <= searchModel.SearchShippingDateTo.Value).ToList();

//            if (!string.IsNullOrEmpty(searchModel.SearchLicencePlate))
//                mockData = mockData.Where(s => s.LicencePlate.Contains(searchModel.SearchLicencePlate, StringComparison.OrdinalIgnoreCase)).ToList();

//            if (searchModel.SearchIsAllMeasured == 1)
//                mockData = mockData.Where(s => s.IsAllMeasured).ToList();
//            else if (searchModel.SearchIsAllMeasured == 2)
//                mockData = mockData.Where(s => !s.IsAllMeasured).ToList();

//            return new PagedList<Shipping>(mockData, searchModel.Page - 1, searchModel.PageSize);
//        }

//        #endregion
//    }
//}
