package dev.inmo.postssystem.features.users.server

import dev.inmo.micro_utils.ktor.server.UnifiedRouter
import dev.inmo.postssystem.features.users.common.*
import dev.inmo.micro_utils.ktor.server.configurators.ApplicationRoutingConfigurator
import dev.inmo.micro_utils.repos.ktor.server.crud.configureReadStandardCrudRepoRoutes
import io.ktor.auth.authenticate
import io.ktor.routing.Route
import io.ktor.routing.route
import kotlinx.serialization.builtins.nullable

class UsersStorageServerRoutesConfigurator(
    private val usersStorage: ReadUsersStorage,
    private val unifiedRouter: UnifiedRouter
) : ApplicationRoutingConfigurator.Element {
    override fun Route.invoke() {
        authenticate {
            route(usersServerPathPart) {
                configureReadStandardCrudRepoRoutes(
                    usersStorage,
                    User.serializer(),
                    User.serializer().nullable,
                    UserId.serializer(),
                    unifiedRouter
                )
            }
        }
    }
}
