package com.wallpaper.wallpaperbox.data.repository;

import androidx.lifecycle.LiveData;

import com.wallpaper.wallpaperbox.data.dao.WallpaperEntityDao;
import com.wallpaper.wallpaperbox.data.entity.WallpaperEntity;

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

public class WallpaperRepository {
    private final WallpaperEntityDao wallpaperEntityDao;
    private final ExecutorService executorService;

    public WallpaperRepository(WallpaperEntityDao wallpaperEntityDao) {
        this.wallpaperEntityDao = wallpaperEntityDao;
        this.executorService = Executors.newSingleThreadExecutor();
    }

    public void insertAll(List<WallpaperEntity> wallpaperEntityList) {
        executorService.execute(() -> wallpaperEntityDao.insertAll(wallpaperEntityList));
    }

    public void update(WallpaperEntity wallpaperEntity) {
        executorService.execute(() -> wallpaperEntityDao.update(wallpaperEntity));
    }

    public LiveData<List<WallpaperEntity>> getFirstWallpaper() {
        return wallpaperEntityDao.getFirstWallpaper();
    }

    public LiveData<List<WallpaperEntity>> getLike() {
        return wallpaperEntityDao.getLike();
    }

    public LiveData<List<WallpaperEntity>> getCategoryByName(String name) {
        return wallpaperEntityDao.getCategoryByName(name);
    }

    public LiveData<Boolean> getWallpaperLike(String source, String name) {
        return wallpaperEntityDao.getWallpaperLike(source, name);
    }
}
