/*
 * ********************************************************************************************************************
 *
 *                      :*$@@%$*:                         ;:                ;;    ;;
 *                    :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
 *                   :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
 *                   =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
 *                   =@*                                  %!              @ $= % %@=   =%@!      %=
 *              *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
 *            %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
 *          ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
 *          $@*   ;@@@%=!:                *@*
 *          =@$    ;;;!=%@@@@=!           =@!
 *           %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2019.  北京上格云技术有限公司
 *            ;%@@$=$@@%*       *@@@$=%@@%;
 *               ::;::             ::;::                                              All rights reserved.
 *
 * ********************************************************************************************************************
 */

package com.persagy.server.sso.users


import com.persagy.server.models.requests.UserChangePasswordRequest
import com.persagy.server.models.requests.UserDeleteRequest
import com.persagy.server.models.requests.UserUpdateRequest
import com.persagy.server.models.responses.BaseResponse
import com.persagy.server.models.responses.UserCreateRequest
import com.persagy.server.models.responses.UserCreateResponse
import com.persagy.server.models.responses.UserInfoResponse
import com.persagy.server.sso.SSoClient
import com.persagy.server.sso.UserService
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.slf4j.LoggerFactory
import org.springframework.web.bind.annotation.*

/**
 * 用户接口
 *
 * @author 庞利祥
 */
@Api(tags = ["用户接口"])
@RestController
@RequestMapping("/user")
class UserController {
    companion object {
        // 日志
        private val logger = LoggerFactory.getLogger(UserController::class.java)
    } // Companion object

    /**
     * 创建用户
     */
    @ApiOperation(value = "创建用户", notes = "")
    @PostMapping(value = ["/create"])
    fun create(@RequestBody request: UserCreateRequest): UserCreateResponse {
        return SSoClient.create(request)
    } // Function create()

    /**
     * 更新用户
     */
    @ApiOperation(value = "更新用户", notes = "")
    @PostMapping(value = ["/update"])
    fun update(@RequestBody request: UserUpdateRequest): BaseResponse {
        return SSoClient.update(request)
    } // Function update()

    /**
     * 删除用户
     */
    @ApiOperation(value = "删除用户", notes = "")
    @PostMapping(value = ["/delete"])
    fun delete(@RequestBody request: UserDeleteRequest): BaseResponse {
        return SSoClient.delete(request)
    } // Function delete()

    /**
     * 修改用户密码
     */
    @ApiOperation(value = "修改用户密码", notes = "")
    @PostMapping(value = ["/changePwd"])
    fun changePwd(@RequestBody request: UserChangePasswordRequest): BaseResponse {
        return SSoClient.changePwd(request)
    } // Function changePwd()

    @ApiOperation(value = "用户登录", notes = "")
    @GetMapping(value = ["/userInfo"])
    // @RequiresPermissions("permission:retrieve")
    fun userInfo(): UserInfoResponse {
        return UserService.userInfo()
    } // Function userInfo

} // Class UserController
