package com.ycwl.basic.controller.pc;

import com.github.pagehelper.PageInfo;

import com.ycwl.basic.annotation.IgnoreToken;
import com.ycwl.basic.model.pc.adminUser.req.*;
import com.ycwl.basic.model.pc.adminUser.resp.AdminUserListRespVO;
import com.ycwl.basic.model.pc.adminUser.resp.StaffSimpleInfoRespVO;
import com.ycwl.basic.service.pc.AdminUserService;
import com.ycwl.basic.utils.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/adminUser/v1")
@Slf4j
@Api(tags = "系统后台用户管理")
public class AdminUserController {

    @Autowired
    AdminUserService adminUserService;


    @PostMapping(value = "/login")
    @ApiOperation(value = "登录")
    @IgnoreToken
    public ApiResponse login(@RequestBody LoginReqVO loginReqVO) throws Exception {
        log.info("{}:开始登录管理后台", loginReqVO.getAccount());
        return adminUserService.login(loginReqVO);
    }

    @PostMapping(value = "/updatePassword")
    @ApiOperation(value = "用户自己修改密码")
    public ApiResponse updatePassword(@RequestBody UpdatePasswordReqVO updatePasswordReqVO) throws Exception {
        log.info("{}:开始修改管理后台密码", updatePasswordReqVO.getId());
        return adminUserService.updatePassword(updatePasswordReqVO);
    }

    @PostMapping(value = "/list")
    @ApiOperation(value = "系统后台用户列表")
    //@IgnoreToken
    public ApiResponse<PageInfo<List<AdminUserListRespVO>>> list(@RequestBody AdminUserListReqVO adminUserListReqVO) {
        return adminUserService.list(adminUserListReqVO);
    }

    @PostMapping(value = "/query/list")
    @ApiOperation(value = "系统后台用户列表查询")
    @IgnoreToken
    public ApiResponse<PageInfo<List<AdminUserListRespVO>>> queryList(@RequestBody AdminUserListReqVO adminUserListReqVO) {
        return adminUserService.list(adminUserListReqVO);
    }

    @PostMapping(value = "/add")
    @ApiOperation(value = "添加系统后台用户")
    //@IgnoreToken
    public ApiResponse add(@RequestBody AddOrUpdateAdminUserReqVO addOrUpdateAdminUserReqVO) {
        return adminUserService.addOrUpdate(addOrUpdateAdminUserReqVO);
    }

    @PostMapping(value = "/update")
    @ApiOperation(value = "更新系统后台用户")
    //@IgnoreToken
    public ApiResponse update(@RequestBody AddOrUpdateAdminUserReqVO addOrUpdateAdminUserReqVO) {
        return adminUserService.addOrUpdate(addOrUpdateAdminUserReqVO);
    }

    @GetMapping(value = "/delete/{id}")
    @ApiOperation(value = "删除")
    //@IgnoreToken
    public ApiResponse delete(@PathVariable("id") String id) {
        return adminUserService.delete(id);
    }

    @PostMapping(value = "/resetPassword")
    @ApiOperation(value = "重置密码")
    //@IgnoreToken
    public ApiResponse resetPassword(@RequestBody ResetPasswordReqVO resetPasswordReqVO) {
        log.info("{}:开始重置后台密码", resetPasswordReqVO.getId());
        return adminUserService.resetPassword(resetPasswordReqVO);
    }


}

