package com.example.petstoremobile.repositories;

import androidx.lifecycle.LiveData;

import com.example.petstoremobile.api.CouponApi;
import com.example.petstoremobile.dtos.CouponDTO;
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 CouponRepository extends BaseRepository {
    private final CouponApi couponApi;

    @Inject
    public CouponRepository(CouponApi couponApi) {
        super("CouponRepository");
        this.couponApi = couponApi;
    }

    public LiveData<Resource<PageResponse<CouponDTO>>> getAllCoupons(int page, int size, Boolean active, String discountType, String sort) {
        return executeCall(couponApi.getAllCoupons(page, size, active, discountType, sort));
    }

    public LiveData<Resource<CouponDTO>> getCouponById(Long id) {
        return executeCall(couponApi.getCouponById(id));
    }

    public LiveData<Resource<CouponDTO>> getCouponByCode(String code) {
        return executeCall(couponApi.getCouponByCode(code));
    }

    public LiveData<Resource<CouponDTO>> createCoupon(CouponDTO coupon) {
        return executeCall(couponApi.createCoupon(coupon));
    }

    public LiveData<Resource<CouponDTO>> updateCoupon(Long id, CouponDTO coupon) {
        return executeCall(couponApi.updateCoupon(id, coupon));
    }

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

    public LiveData<Resource<Void>> bulkDeleteCoupons(List<Long> ids) {
        return executeCall(couponApi.bulkDeleteCoupons(ids));
    }
}
