package com.tuoheng.controller;

import com.tuoheng.model.dto.LoginUser;
import com.tuoheng.model.param.CreateClientUserDto;
import com.tuoheng.model.param.UpdateUserClientRoleDto;
import com.tuoheng.model.param.UpdateUserPassDto;
import com.tuoheng.service.ClientUserSevice;
import com.tuoheng.service.CurrentUser;
import com.tuoheng.until.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author chenjiandong
 * @description: 同步业务端 user 数据
 * @date 2022/10/24 11:12
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private ClientUserSevice clientUserSevice;

    @GetMapping("/judge/create/{username}")
    public JsonResult judgeCreate(@PathVariable("username") String username){
        return clientUserSevice.judgeCreate(username);
    }

    @PostMapping("/create")
    public JsonResult createClientUser(@RequestBody CreateClientUserDto createClientUserDto,
                                       @CurrentUser LoginUser loginUser){
        return clientUserSevice.createClientUser(createClientUserDto, loginUser);
    }

    @PostMapping("/updatePass")
    public JsonResult updateUserPassword(@RequestBody @Validated UpdateUserPassDto updateUserPassDto,
                                         @CurrentUser LoginUser loginUser){
        return clientUserSevice.updateUserPassword(updateUserPassDto, loginUser);
    }

    @PostMapping("/updateRole")
    public JsonResult updateUserClientRole(@RequestBody @Validated UpdateUserClientRoleDto updateUserClientRoleDto,
                                           @CurrentUser LoginUser loginUser){
        return clientUserSevice.updateUserClientRole(updateUserClientRoleDto, loginUser);
    }

}
