package com.example.petstoremobile.repositories;

import androidx.lifecycle.LiveData;

import com.example.petstoremobile.api.CustomerApi;
import com.example.petstoremobile.dtos.CustomerDTO;
import com.example.petstoremobile.dtos.DropdownDTO;
import com.example.petstoremobile.dtos.PageResponse;
import com.example.petstoremobile.utils.Resource;

import java.util.List;

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

@Singleton
public class CustomerRepository extends BaseRepository {
    private final CustomerApi customerApi;

    @Inject
    public CustomerRepository(CustomerApi customerApi) {
        super("CustomerRepository");
        this.customerApi = customerApi;
    }

    public LiveData<Resource<PageResponse<CustomerDTO>>> getAllCustomers(int page, int size) {
        return executeCall(customerApi.getAllCustomers(page, size));
    }

    public LiveData<Resource<CustomerDTO>> getCustomerById(Long id) {
        return executeCall(customerApi.getCustomerById(id));
    }

    public LiveData<Resource<CustomerDTO>> createCustomer(CustomerDTO dto) {
        return executeCall(customerApi.registerCustomer(dto));
    }

    public LiveData<Resource<CustomerDTO>> updateCustomer(Long id, CustomerDTO dto) {
        return executeCall(customerApi.updateCustomer(id, dto));
    }

    public LiveData<Resource<Void>> deleteCustomer(Long id) {
        return executeCall(customerApi.deleteCustomer(id));
    }

    public LiveData<Resource<List<DropdownDTO>>> getCustomerDropdowns() {
        return executeCall(customerApi.getCustomerDropdowns());
    }
}
