package com.example.petstoremobile.repositories;

import androidx.lifecycle.LiveData;

import com.example.petstoremobile.api.SupplierApi;
import com.example.petstoremobile.dtos.BulkDeleteRequest;
import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.dtos.SupplierDTO;
import com.example.petstoremobile.utils.Resource;

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

@Singleton
public class SupplierRepository extends BaseRepository {
    private final SupplierApi supplierApi;

    @Inject
    public SupplierRepository(SupplierApi supplierApi) {
        super("SupplierRepository");
        this.supplierApi = supplierApi;
    }

    /**
     * Retrieves a paginated list of all suppliers from the API.
     */
    public LiveData<Resource<PageResponse<SupplierDTO>>> getAllSuppliers(int page, int size, String query, String sort) {
        return executeCall(supplierApi.getAllSuppliers(page, size, query, sort));
    }

    /**
     * Retrieves a specific supplier by its ID from the API.
     */
    public LiveData<Resource<SupplierDTO>> getSupplierById(Long id) {
        return executeCall(supplierApi.getSupplierById(id));
    }

    /**
     * Sends a request to the API to create a new supplier record.
     */
    public LiveData<Resource<SupplierDTO>> createSupplier(SupplierDTO supplier) {
        return executeCall(supplierApi.createSupplier(supplier));
    }

    /**
     * Sends a request to the API to update an existing supplier record by ID.
     */
    public LiveData<Resource<SupplierDTO>> updateSupplier(Long id, SupplierDTO supplier) {
        return executeCall(supplierApi.updateSupplier(id, supplier));
    }

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

    /**
     * Sends a request to the API to delete multiple supplier records.
     */
    public LiveData<Resource<Void>> bulkDeleteSuppliers(BulkDeleteRequest request) {
        return executeCall(supplierApi.bulkDeleteSuppliers(request));
    }
}
