package com.prank.happypranksounds.data.database;

import android.content.Context;

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

import com.prank.happypranksounds.MyApplication;
import com.prank.happypranksounds.data.dao.HappyDataDao;
import com.prank.happypranksounds.data.entity.HappyData;

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

    public abstract HappyDataDao happyDataDao();

    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.DATABASE_NAME)
                            .build();
                }
            }
        }
        return INSTANCE;
    }
}
