package com.example.pmulabs.room

import android.content.Context
import com.example.pmulabs.room.database.NewsPortalDatabase
import com.example.pmulabs.room.repository.ArticleRepository
import com.example.pmulabs.room.repository.CommentRepository
import com.example.pmulabs.room.repository.OfflineArticleRepository
import com.example.pmulabs.room.repository.OfflineCommentRepository
import com.example.pmulabs.room.repository.OfflineTagRepository
import com.example.pmulabs.room.repository.OfflineUserRepository
import com.example.pmulabs.room.repository.TagRepository
import com.example.pmulabs.room.repository.UserRepository

interface AppContainer {
    val userRepository: UserRepository
    val articleRepository: ArticleRepository
    val tagRepository: TagRepository
    val commentRepository: CommentRepository
}

class AppDataContainer(private val context: Context) : AppContainer {
    override val userRepository: UserRepository by lazy {
        OfflineUserRepository(NewsPortalDatabase.getInstance(context).userDao())
    }
    override val articleRepository: ArticleRepository by lazy {
        OfflineArticleRepository(NewsPortalDatabase.getInstance(context).articleDao())
    }
    override val tagRepository: TagRepository by lazy {
        OfflineTagRepository(NewsPortalDatabase.getInstance(context).tagDao())
    }
    override val commentRepository: CommentRepository by lazy {
        OfflineCommentRepository(NewsPortalDatabase.getInstance(context).commentDao())
    }

    companion object {
        const val TIMEOUT = 5000L
    }
}