package com.prank.happypranksounds.ui.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;

import com.prank.happypranksounds.data.dao.HappyDataDao;
import com.prank.happypranksounds.data.database.AppDatabase;
import com.prank.happypranksounds.data.entity.HappyData;
import com.prank.happypranksounds.data.repository.HappyRepository;

import java.util.List;

public class HappyViewModel extends AndroidViewModel {
    private final HappyRepository happyRepository;

    public HappyViewModel(@NonNull Application application) {
        super(application);
        HappyDataDao wallpaperInfoDao = AppDatabase.getInstance(application).happyDataDao();
        happyRepository = new HappyRepository(wallpaperInfoDao);
    }

    public void insert(HappyData happyData) {
        happyRepository.insert(happyData);
    }

    public void update(HappyData happyData) {
        happyRepository.update(happyData);
    }

    public void delete(HappyData happyData) {
        happyRepository.delete(happyData);
    }

    public LiveData<List<HappyData>> getFavorite() {
        return happyRepository.getFavorite();
    }

    public LiveData<List<HappyData>> getFirstCategory() {
        return happyRepository.getFirstCategory();
    }

    public LiveData<List<HappyData>> getCategoryList(String name) {
        return happyRepository.getCategoryList(name);
    }

    public boolean toggleFavorite(@NonNull HappyData happyData) {
        boolean isFavorite = !happyData.isFavorite();
        happyData.setFavorite(isFavorite);
        happyRepository.update(happyData);
        return isFavorite;
    }

    public LiveData<List<HappyData>> getExternal() {
        return happyRepository.getExternal();
    }

    public void getCountAsync(String uri, HappyRepository.CountCallback callback) {
        happyRepository.getCountAsync(uri, callback);
    }
}
