package com.example.petstoremobile.repositories;

import androidx.lifecycle.LiveData;

import com.example.petstoremobile.api.ProductSupplierApi;
import com.example.petstoremobile.dtos.BulkDeleteRequest;
import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.dtos.ProductSupplierDTO;
import com.example.petstoremobile.utils.Resource;

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

@Singleton
public class ProductSupplierRepository extends BaseRepository {
    private final ProductSupplierApi api;

    @Inject
    public ProductSupplierRepository(ProductSupplierApi api) {
        super("ProductSupplierRepository");
        this.api = api;
    }

    /**
     * Retrieves a paginated list of all product-supplier relationships from the API.
     */
    public LiveData<Resource<PageResponse<ProductSupplierDTO>>> getAllProductSuppliers(int page, int size, String query, Long productId, Long supplierId, String sort) {
        return executeCall(api.getAllProductSuppliers(page, size, query, productId, supplierId, sort));
    }

    /**
     * Retrieves a single product-supplier relationship by product and supplier IDs.
     */
    public LiveData<Resource<ProductSupplierDTO>> getProductSupplierById(Long productId, Long supplierId) {
        return executeCall(api.getProductSupplierById(productId, supplierId));
    }

    /**
     * Sends a request to the API to create a new product-supplier relationship.
     */
    public LiveData<Resource<ProductSupplierDTO>> createProductSupplier(ProductSupplierDTO dto) {
        return executeCall(api.createProductSupplier(dto));
    }

    /**
     * Sends a request to the API to update an existing product-supplier relationship.
     */
    public LiveData<Resource<ProductSupplierDTO>> updateProductSupplier(Long productId, Long supplierId, ProductSupplierDTO dto) {
        return executeCall(api.updateProductSupplier(productId, supplierId, dto));
    }

    /**
     * Sends a request to the API to delete a specific product-supplier relationship.
     */
    public LiveData<Resource<Void>> deleteProductSupplier(Long productId, Long supplierId) {
        return executeCall(api.deleteProductSupplier(productId, supplierId));
    }

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