package com.om.controller.admin;


import com.om.entity.dto.AdminAddDTO;
import com.om.entity.dto.AdminQueryPageDTO;
import com.om.entity.vo.AdminLoginVO;
import com.om.entity.vo.AdminQueryPageVO;
import com.om.service.IAdminService;
import com.om.utils.AdminContext;
import com.om.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bmmx
 * @since 2024-01-26
 */
@RestController
@Api(tags = "后台管理系统用户模块接口")
@RequestMapping("/web/manager")
public class AdminController {

    @Resource
    private IAdminService adminService;


    @GetMapping("/login")
    @ApiOperation("管理员登录")
    public Result<AdminLoginVO> login(@RequestParam String username, @RequestParam String password){
        return adminService.login(username,password);
    }


    @GetMapping("getManagerByToken")
    @ApiOperation("通过token获取管理员信息")
    public Result<AdminLoginVO> getManagerByToken(@RequestParam String token){
        return adminService.getManagerByToken(token);
    }

    @PostMapping("add")
    @ApiOperation("添加管理员信息")
    public Result add(@Validated @RequestBody AdminAddDTO dto){
        return adminService.add(dto);
    }

    @GetMapping("delete")
    @ApiOperation("删除管理员信息")
    public Result delete(@RequestParam Integer id){
        return adminService.delete(id);
    }

    @GetMapping("get")
    @ApiOperation("根据id查询管理员信息")
    public Result<AdminLoginVO> get(@RequestParam Integer id){
        return adminService.get(id);
    }

    @PostMapping("getPageList")
    @ApiOperation("分页查询管理员列表")
    public Result<AdminQueryPageVO> getPageList(@RequestBody AdminQueryPageDTO dto) {
        return adminService.getPageList(dto);
    }

    @PostMapping("update")
    @ApiOperation("修改管理员信息")
    public Result<AdminLoginVO> updateAdmin(@Validated @RequestBody AdminAddDTO dto){
        return adminService.updateAdmin(dto);
    }

    @GetMapping("updateState")
    @ApiOperation("修改管理员状态")
    public Result updateState(@RequestParam Integer id){
        return adminService.updateState(id);
    }

    @GetMapping("logout")
    @ApiOperation("管理员退出登录")
    public Result logout(@RequestParam Integer id){
        return adminService.logout(id);
    }


}
