package com.ardrawing.ardrawingspace.viewmodel;

import android.app.Application;

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

import com.ardrawing.ardrawingspace.room.AppDatabase;
import com.ardrawing.ardrawingspace.room.SpaceEntity;
import com.ardrawing.ardrawingspace.room.SpaceEntityDao;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class SpaceViewModel extends AndroidViewModel {
    private final SpaceEntityDao dao;
    private final ExecutorService executorService;

    public SpaceViewModel(@NonNull Application application) {
        super(application);
        dao = AppDatabase.getInstance(application).dao();
        this.executorService = Executors.newSingleThreadExecutor();
    }

    public void insert(SpaceEntity spaceEntity) {
        executorService.execute(() -> dao.insert(spaceEntity));
    }

    public void delete(SpaceEntity spaceEntity) {
        executorService.execute(() -> dao.delete(spaceEntity));
    }

    public LiveData<List<SpaceEntity>> getFavorite() {
        return dao.getFavorite();
    }

    public LiveData<List<SpaceEntity>> getEntityByImagePath(String name) {
        return dao.getEntityByImagePath(name);
    }

    public LiveData<List<SpaceEntity>> getMinById() {
        return dao.getMinById();
    }

    public LiveData<List<SpaceEntity>> getImportLiveData() {
        return dao.getImportLiveData();
    }

    public List<SpaceEntity> getImport() {
        return dao.getImport();
    }

}
