package com.wallpaper.wallpaperbox.data.database;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

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

@Database(entities = {WallpaperEntity.class}, version = MyApplication.DB_VERSION, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {

    public abstract WallpaperEntityDao wallpaperEntityDao();
    private static volatile AppDatabase INSTANCE;

    public static AppDatabase getInstance(Context context) {
        if (INSTANCE == null) {
            synchronized (AppDatabase.class) {
                if (INSTANCE == null) {
                    INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                                    AppDatabase.class, MyApplication.DB_NAME)
                            .build();
                }
            }
        }
        return INSTANCE;
    }
}
