package com.jishisongfu.duobibi.di

import android.content.Context
import androidx.room.Room
import com.jishisongfu.duobibi.data.db.AppDatabase
import com.jishisongfu.duobibi.data.db.ClusterDao
import com.jishisongfu.duobibi.data.db.PriceAlertDao
import com.jishisongfu.duobibi.data.db.PriceRecordDao
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 ctx: Context): AppDatabase =
        // 全新 App,单一 schema version 1,无迁移
        Room.databaseBuilder(ctx, AppDatabase::class.java, "duobibi.db").build()

    @Provides
    fun providePriceRecordDao(db: AppDatabase): PriceRecordDao = db.priceRecordDao()

    @Provides
    fun provideClusterDao(db: AppDatabase): ClusterDao = db.clusterDao()

    @Provides
    fun providePriceAlertDao(db: AppDatabase): PriceAlertDao = db.priceAlertDao()
}
