package com.example.ops_android

import android.content.Context
import com.example.ops_android.data.cache.UserCache
import com.example.ops_android.data.local.SessionManager
import com.example.ops_android.data.remote.ApiServiceFactory
import com.example.ops_android.data.remote.api.*
import com.example.ops_android.data.repository.*
import com.example.ops_android.printer.PrinterManager
import kotlinx.coroutines.runBlocking

class AppContainer(context: Context) {
    val sessionManager = SessionManager(context)
    private val apiServiceFactory = ApiServiceFactory(sessionManager)

    val userApi by lazy { apiServiceFactory.create<UserApi>() }
    val usersApi by lazy { apiServiceFactory.create<UsersApi>() }
    val purchaseApi by lazy { apiServiceFactory.create<PurchaseApi>() }
    val workOrderApi by lazy { apiServiceFactory.create<WorkOrderApi>() }
    val warehouseApi by lazy { apiServiceFactory.create<WarehouseApi>() }
    val customerApi by lazy { apiServiceFactory.create<CustomerApi>() }
    val scheduleApi by lazy { apiServiceFactory.create<ScheduleApi>() }
    val fileApi by lazy { apiServiceFactory.create<FileApi>() }

    val authRepository by lazy { AuthRepository(userApi, sessionManager) }
    val orderRepository by lazy { OrderRepository(purchaseApi) }
    val workOrderRepository by lazy { WorkOrderRepository(workOrderApi) }
    val warehouseRepository by lazy { WarehouseRepository(warehouseApi) }
    val customerRepository by lazy { CustomerRepository(customerApi) }
    val scheduleRepository by lazy { ScheduleRepository(scheduleApi) }
    val userCache by lazy { UserCache(usersApi) }

    var printerManager: PrinterManager? = null

    init {
        runBlocking { sessionManager.init() }
    }
}
