package com.example.petstoremobile.repositories;

import androidx.lifecycle.LiveData;

import com.example.petstoremobile.api.AppointmentApi;
import com.example.petstoremobile.dtos.AppointmentDTO;
import com.example.petstoremobile.dtos.BulkDeleteRequest;
import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.utils.Resource;

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

@Singleton
public class AppointmentRepository extends BaseRepository {
    private final AppointmentApi appointmentApi;

    @Inject
    public AppointmentRepository(AppointmentApi appointmentApi) {
        super("AppointmentRepository");
        this.appointmentApi = appointmentApi;
    }

    /**
     * Retrieves a paginated list of all appointments from the API with filtering.
     */
    public LiveData<Resource<PageResponse<AppointmentDTO>>> getAllAppointments(int page, int size, String query, String status, Long storeId, String date, Long employeeId, String sort) {
        return executeCall(appointmentApi.getAllAppointments(page, size, query, status, storeId, date, employeeId, sort));
    }

    /**
     * Retrieves a specific appointment by its ID from the API.
     */
    public LiveData<Resource<AppointmentDTO>> getAppointmentById(Long id) {
        return executeCall(appointmentApi.getAppointmentById(id));
    }

    /**
     * Sends a request to the API to create a new appointment record.
     */
    public LiveData<Resource<AppointmentDTO>> createAppointment(AppointmentDTO appointment) {
        return executeCall(appointmentApi.createAppointment(appointment));
    }

    /**
     * Sends a request to the API to update an existing appointment record by ID.
     */
    public LiveData<Resource<AppointmentDTO>> updateAppointment(Long id, AppointmentDTO appointment) {
        return executeCall(appointmentApi.updateAppointment(id, appointment));
    }

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

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