package com.ruoyi.api.controller.user;

import com.ruoyi.api.controller.common.AbstractApiController;
import com.ruoyi.clock.domain.bo.EmployeeBo;
import com.ruoyi.clock.domain.bo.EmployeePasswordBo;
import com.ruoyi.clock.domain.vo.EmployeeVo;
import com.ruoyi.clock.service.IEmployeeService;
import com.ruoyi.common.apiencrypt.annotation.ApiDecrypt;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 小程序用户管理Controller
 *
 * @author wuchao
 * @date 2022-03-03
 */
@Validated
@Api(value = "小程序用户管理控制器", tags = {"小程序用户管理管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/miniapp/user")
public class ApiUserController extends AbstractApiController {

    private final IEmployeeService employeeService;

    /**
     * 获取用户管理详细信息
     */
    @ApiOperation("获取用户管理详细信息")
    @GetMapping("/info")
    public R<EmployeeVo> getInfo() {
        EmployeeVo employeeVo = employeeService.queryById(getUserId());
        employeeVo.loadAgentVo();
        employeeVo.loadShopVo();
        return R.ok(employeeVo);
    }

    /**
     * 编辑姓名
     */
    @ApiOperation("修改店员信息")
    @PostMapping("/edit")
    public R<Boolean> edit(@Validated(EditGroup.class) @RequestBody EmployeeBo bo) {
        Long userId = getUserId();
        bo.setEmployeeName(bo.getEmployeeName());
        bo.setEmployeeId(userId);
        bo.setAvatar(bo.getAvatar());
        return R.ok(employeeService.updateByBo(bo));
    }

    /**
     * 修改密码
     */
    @ApiOperation("修改密码")
    @PostMapping("/updatePwd")
    public R<Boolean> updatePwd(@RequestBody EmployeePasswordBo bo) {
        bo.setEmployeeId(getUserId());
        return R.ok(employeeService.updatePwd(bo));
    }

}
