package gaf3.core.services.api

import gaf3.core.cloud.feign.GafFeignConfiguration
import gaf3.core.data.JsonResult
import gaf3.core.data.PagedData
import gaf3.core.services.api.domain.AcctForm
import gaf3.core.services.api.domain.UserForm
import gaf3.core.services.api.domain.UserInfo
import org.springframework.cloud.openfeign.FeignClient
import org.springframework.web.bind.annotation.*

@FeignClient(name = "\${feign.name}", url = "\${feign.url}", configuration = [GafFeignConfiguration::class] )
interface UserService {
    @PostMapping(path = ["/gaf/users"])
    fun createUser(@RequestBody data: UserForm): UserInfo

    @GetMapping(path = ["/gaf/users"])
    fun findUsers(filter: UserInfo? = null, skip: Int = 0, limit: Int = 100): PagedData<UserInfo>

    @DeleteMapping(path = ["/gaf/users/{userId}"])
    fun deleteUser(@PathVariable userId: String): JsonResult<Void>

    @GetMapping(path = ["/gaf/users/{userId}"])
    fun updateUser(@PathVariable userId: String, @RequestBody data: UserForm): UserInfo

    @GetMapping(path = ["/gaf/users/{userId}"])
    fun fetchUser(@PathVariable userId: String): UserInfo?

    @PostMapping(path = ["/gaf/users/{userId}/pass"])
    fun changePass(@PathVariable userId: String, oldpass: String, newpass: String): JsonResult<Void>

    @PostMapping(path = ["/gaf/users/{userId}/acct"])
    fun updateAcct(@PathVariable userId: String, @RequestBody data: AcctForm): JsonResult<Void>

    @PostMapping(path = ["/gaf/users/login"])
    fun login(@RequestBody data: AcctForm): JsonResult<UserInfo>
}