package com.example.petstoremobile.repositories;

import androidx.lifecycle.LiveData;

import com.example.petstoremobile.api.ServiceApi;
import com.example.petstoremobile.dtos.BulkDeleteRequest;
import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.dtos.ServiceDTO;
import com.example.petstoremobile.utils.Resource;

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

@Singleton
public class ServiceRepository extends BaseRepository {
    private final ServiceApi serviceApi;

    @Inject
    public ServiceRepository(ServiceApi serviceApi) {
        super("ServiceRepository");
        this.serviceApi = serviceApi;
    }

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

    /**
     * Retrieves a specific service by its ID from the API.
     */
    public LiveData<Resource<ServiceDTO>> getServiceById(Long id) {
        return executeCall(serviceApi.getServiceById(id));
    }

    /**
     * Sends a request to the API to create a new service.
     */
    public LiveData<Resource<ServiceDTO>> createService(ServiceDTO service) {
        return executeCall(serviceApi.createService(service));
    }

    /**
     * Sends a request to the API to update an existing service by ID.
     */
    public LiveData<Resource<ServiceDTO>> updateService(Long id, ServiceDTO service) {
        return executeCall(serviceApi.updateService(id, service));
    }

    /**
     * Sends a request to the API to delete a specific service.
     */
    public LiveData<Resource<Void>> deleteService(Long id) {
        return executeCall(serviceApi.deleteService(id));
    }

    /**
     * Sends a request to the API to delete multiple services.
     */
    public LiveData<Resource<Void>> bulkDeleteServices(BulkDeleteRequest request) {
        return executeCall(serviceApi.bulkDeleteServices(request));
    }
}
