package dev.inmo.postssystem.client

import dev.inmo.postssystem.features.users.common.ReadUsersStorage
import dev.inmo.micro_utils.repos.pagination.getAll
import org.koin.core.context.startKoin

fun readLine(suggestionText: String): String {
    while (true) {
        println(suggestionText)
        readLine() ?.let { return it }
    }
}

suspend fun main(args: Array<String>) {
    val serverUrl = readLine("Server url:")
    val login = readLine("Username:")
    val password = readLine("Password:")

    val koin = startKoin {
//        modules(getAuthorizedFeaturesDIModule(serverUrl, AuthCreds(Username(login), password)))
    }.koin

    while (true) {
        val chosen = readLine(
            """
                Choose action:
                1. Show server users
            """.trimIndent()
        ).toIntOrNull()
        when (chosen) {
            1 -> println(koin.get<ReadUsersStorage>().getAll { getByPagination(it) })
            else -> println("Sorry, I didn't understand")
        }
    }
}
