using Distribution.Features.Stock; using Distribution.Infra.UoW; using Distribution.Models; namespace Distribution.Features.ShopPO; public class ShopPOService( IShopPORepository repo, IUnitOfWork uow) { private static ShopPOResponse ToResponse(Models.ShopPO p) => new(p.Id, p.FK_StoreId, p.Store?.StoreName ?? string.Empty, p.RaisedById, p.InvoiceId, p.TotalAmount, p.Status, p.ConfirmedAt, p.ConfirmedBy, p.FulfilledAt, p.Items.Where(i => i.IsActive).Select(i => new ShopPOItemResponse(i.Id, i.FK_ItemId, i.Item?.Name ?? string.Empty, i.Quantity, i.QuantityFulfilled, i.UnitPrice, i.IsActive)).ToList(), p.IsActive, p.CreatedAt); public async Task> GetAllAsync(Guid? agentId, Guid? routeId, Guid? shopId, bool? confirmed, int page, int pageSize) { var total = await repo.GetCountAsync(agentId, routeId, shopId, confirmed); var items = await repo.GetAllAsync(agentId, routeId, shopId, confirmed, page, pageSize); return new PagedResponse(page, pageSize, total, items.Select(ToResponse).ToList()); } public async Task GetByIdAsync(Guid id) { var po = await repo.GetByIdAsync(id); return po is null ? null : ToResponse(po); } }