package com.nebula.erp.inventory.service;

import com.nebula.erp.inventory.model.Inventory;
import com.nebula.erp.inventory.repository.InventoryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

@Service
public class PublicInventoryService {

    @Autowired
    private InventoryRepository inventoryRepository;

    public List<Map<String, Object>> getInventoriesByTenant(String tenantName) {
        List<Inventory> inventories = inventoryRepository
                .findAllByTenant(Pageable.unpaged(), tenantName);

        return inventories.stream().map(inventory -> {
            Map<String, Object> itemData = new LinkedHashMap<>();
            itemData.put("product_id", inventory.getProduct_id());
            itemData.put("total_quantity", inventory.getTotal_quantity());
            return itemData;
        }).collect(Collectors.toList());
    }
}