package com.tenlionsoft.baselib.core.db;

import android.content.Context;

import com.tenlionsoft.baselib.core.db.beans.FoodCanteenBean;
import com.tenlionsoft.baselib.core.db.beans.FoodFoodBean;
import com.tenlionsoft.baselib.core.db.beans.FoodPublishBean;
import com.tenlionsoft.baselib.core.db.beans.FoodPublishFoodBean;
import com.tenlionsoft.baselib.core.db.beans.FoodSubscribeBean;
import com.tenlionsoft.baselib.core.db.beans.FoodSubscribeFoodBean;
import com.tenlionsoft.baselib.core.db.beans.LocalMediaBean;
import com.tenlionsoft.baselib.core.db.beans.UserAccountBean;
import com.tenlionsoft.baselib.core.db.beans.UserAccountItemBean;
import com.tenlionsoft.baselib.core.db.beans.UserChargeBean;
import com.tenlionsoft.baselib.core.db.daos.FoodCanteenDao;
import com.tenlionsoft.baselib.core.db.daos.FoodFoodDao;
import com.tenlionsoft.baselib.core.db.daos.FoodPublishDao;
import com.tenlionsoft.baselib.core.db.daos.FoodPublishFoodDao;
import com.tenlionsoft.baselib.core.db.daos.FoodSubscribeDao;
import com.tenlionsoft.baselib.core.db.daos.FoodSubscribeFoodDao;
import com.tenlionsoft.baselib.core.db.daos.LocalMediaDao;
import com.tenlionsoft.baselib.core.db.daos.UserAccountDao;
import com.tenlionsoft.baselib.core.db.daos.UserAccountItemDao;
import com.tenlionsoft.baselib.core.db.daos.UserChargeDao;

import org.jetbrains.annotations.NotNull;

import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;

/**
 * 作者: adam
 * 日期: 1/18/21 - 5:38 PM
 * 邮箱: itgaojian@163.com
 * 描述:
 */
@Database(entities = {
    FoodCanteenBean.class,
    FoodFoodBean.class,
    FoodPublishBean.class,
    FoodPublishFoodBean.class,
    FoodSubscribeBean.class,
    FoodSubscribeFoodBean.class,
    UserAccountBean.class,
    UserAccountItemBean.class,
    UserChargeBean.class,
    LocalMediaBean.class}, version = 2)
public abstract class AppDatabase extends RoomDatabase {

    public abstract FoodCanteenDao getFoodCanteenDao();//食堂信息

    public abstract FoodFoodDao getFoodFoodDao();//菜品

    public abstract FoodPublishDao getFoodPublishDao();//菜单

    public abstract FoodPublishFoodDao getFoodPublishFoodDao();//菜单菜品

    public abstract FoodSubscribeDao getFoodSubscribeDao();//订单

    public abstract FoodSubscribeFoodDao getFoodSubscribeFoodDao();//订单关联菜品

    public abstract UserAccountDao getUserAccountDao();//账户

    public abstract UserAccountItemDao getUserAccountItemDao();//账户流水

    public abstract UserChargeDao getUserChargeDao();//账户充值记录

    public abstract LocalMediaDao getLocalMediaDao();//本地下载的媒体记录

    private static AppDatabase mInstance;

    public static AppDatabase getInstance(Context ctx) {
        if (mInstance == null) {
            synchronized (AppDatabase.class) {
                if (mInstance == null) {
                    mInstance = Room.databaseBuilder(ctx, AppDatabase.class, "sys_police_food.db")
                        .allowMainThreadQueries()
                        .build();
                }
            }
        }
        return mInstance;
    }

    static final Migration MIGRATION_1_2 = new Migration(1, 2) {
        @Override
        public void migrate(@NonNull @NotNull SupportSQLiteDatabase database) {
        }
    };


}
