package llc.arma.fleet.monitor.presentation.graphql

import llc.arma.fleet.monitor.data.entity.SortDirection
import llc.arma.fleet.monitor.data.entity.UserEntity
import llc.arma.fleet.monitor.data.entity.UserRole
import llc.arma.fleet.monitor.data.entity.UserSortField
import llc.arma.fleet.monitor.domain.service.UserService
import llc.arma.fleet.monitor.presentation.model.CreateUserPayload
import llc.arma.fleet.monitor.presentation.model.UpdateUserPayload
import llc.arma.fleet.monitor.presentation.model.UsersPage
import org.springframework.graphql.data.method.annotation.Argument
import org.springframework.graphql.data.method.annotation.MutationMapping
import org.springframework.graphql.data.method.annotation.QueryMapping
import org.springframework.stereotype.Controller

@Controller
class UserGraphQlController(
    private val userService: UserService,
) {
    @QueryMapping
    fun getUsers(
        @Argument page: Int,
        @Argument pageSize: Int?,
        @Argument query: String?,
        @Argument roles: List<UserRole>?,
        @Argument sortDirection: SortDirection,
        @Argument sortField: UserSortField,
    ): UsersPage = userService.getUsers(page, pageSize, query, roles, sortDirection, sortField)

    @QueryMapping
    fun getUser(@Argument id: Long): UserEntity? = userService.getUser(id)

    @MutationMapping
    fun createUser(@Argument payload: CreateUserPayload): UserEntity = userService.createUser(payload)

    @MutationMapping
    fun updateUser(@Argument id: Long, @Argument payload: UpdateUserPayload): UserEntity = userService.updateUser(id, payload)

    @MutationMapping
    fun deleteUser(@Argument id: Long): Boolean = userService.deleteUser(id)
}
