package com.grigowashere.aismap.data;

import android.content.Context;

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

import com.grigowashere.aismap.data.dao.AISVesselDao;
import com.grigowashere.aismap.data.dao.VesselDao;
import com.grigowashere.aismap.data.entity.AISVesselEntity;
import com.grigowashere.aismap.data.entity.VesselEntity;

@Database(entities = {AISVesselEntity.class, VesselEntity.class}, version = 3, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
	public abstract AISVesselDao aisVesselDao();
	public abstract VesselDao vesselDao();

	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,
						"aismap.db"
					).fallbackToDestructiveMigration().build();
				}
			}
		}
		return INSTANCE;
	}
}


