package com.omixlab.lckcontrol.di

import android.content.Context
import androidx.room.Room
import com.omixlab.lckcontrol.data.local.LckDatabase
import com.omixlab.lckcontrol.data.local.dao.LinkedAccountDao
import com.omixlab.lckcontrol.data.local.dao.StreamPlanDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object DatabaseModule {

    @Provides
    @Singleton
    fun provideDatabase(@ApplicationContext context: Context): LckDatabase =
        Room.databaseBuilder(context, LckDatabase::class.java, "lck_control.db")
            .addMigrations(LckDatabase.MIGRATION_1_2, LckDatabase.MIGRATION_2_3, LckDatabase.MIGRATION_3_4, LckDatabase.MIGRATION_4_5, LckDatabase.MIGRATION_5_6)
            .build()

    @Provides
    fun provideLinkedAccountDao(db: LckDatabase): LinkedAccountDao = db.linkedAccountDao()

    @Provides
    fun provideStreamPlanDao(db: LckDatabase): StreamPlanDao = db.streamPlanDao()
}
