package com.prank.funnypranksounds.viewmodel;

import android.app.Application;

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

import com.prank.funnypranksounds.data.local.entity.AudioData;
import com.prank.funnypranksounds.data.repository.AudioRepository;

import java.util.List;

public class AudioViewModel extends AndroidViewModel {

    private final AudioRepository audioRepository;

    public AudioViewModel(@NonNull Application application) {
        super(application);
        audioRepository = new AudioRepository(application);
    }

    public void insert(AudioData audioData) {
        audioRepository.insert(audioData);
    }

    public void update(AudioData audioData) {
        audioRepository.update(audioData);
    }

    public LiveData<List<AudioData>> getFirstCategory() {
        return audioRepository.getFirstCategory();
    }

    public LiveData<List<AudioData>> getCategory(String name) {
        return audioRepository.getCategory(name);
    }

    public LiveData<List<AudioData>> getFavorite() {
        return audioRepository.getFavorite();
    }

    public boolean toggleFavorite(AudioData audioData) {
        boolean isFavorite = !audioData.isFavorite();
        audioData.setFavorite(isFavorite);
        audioRepository.update(audioData);
        return isFavorite;
    }

    public void getCountAsync(String uri, AudioRepository.CountCallback callback) {
        audioRepository.getCountAsync(uri, callback);
    }

    public LiveData<List<AudioData>> getExternal() {
        return audioRepository.getExternal();
    }

    public void delete(AudioData audioData){
        audioRepository.delete(audioData);
    }

}
