package com.example.petstoremobile.repositories;

import androidx.lifecycle.LiveData;

import com.example.petstoremobile.api.InventoryApi;
import com.example.petstoremobile.dtos.BulkDeleteRequest;
import com.example.petstoremobile.dtos.InventoryDTO;
import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.utils.Resource;

import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class InventoryRepository extends BaseRepository {
    private final InventoryApi inventoryApi;

    @Inject
    public InventoryRepository(InventoryApi inventoryApi) {
        super("InventoryRepository");
        this.inventoryApi = inventoryApi;
    }

    /**
     * Retrieves a paginated list of inventory items from the API with optional search, category, storeId and sort.
     */
    public LiveData<Resource<PageResponse<InventoryDTO>>> getAllInventory(String query, Long storeId, int page, int size, String sort) {
        return executeCall(inventoryApi.getAllInventory(page, size, query, storeId, sort));
    }

    /**
     * Retrieves a specific inventory item by its ID from the API.
     */
    public LiveData<Resource<InventoryDTO>> getInventoryById(Long id) {
        return executeCall(inventoryApi.getInventoryById(id));
    }

    /**
     * Sends a request to the API to create a new inventory record.
     */
    public LiveData<Resource<InventoryDTO>> createInventory(InventoryDTO request) {
        return executeCall(inventoryApi.createInventory(request));
    }

    public LiveData<Resource<InventoryDTO>> updateInventory(Long id, InventoryDTO request) {
        return executeCall(inventoryApi.updateInventory(id, request));
    }

    /**
     * Sends a request to the API to delete a specific inventory record.
     */
    public LiveData<Resource<Void>> deleteInventory(Long id) {
        return executeCall(inventoryApi.deleteInventory(id));
    }

    public LiveData<Resource<Void>> bulkDeleteInventory(BulkDeleteRequest request) {
        return executeCall(inventoryApi.bulkDeleteInventory(request));
    }
}
