package com.changhu.module.miniProgram.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.changhu.common.annotation.IsWhiteList;
import com.changhu.common.annotation.JsonBody;
import com.changhu.module.miniProgram.pojo.params.SecurityUserSaveOrUpdateParams;
import com.changhu.module.miniProgram.pojo.params.UserRegisterParams;
import com.changhu.module.miniProgram.pojo.queryParams.ServiceProjectSecurityUserPagerQueryParams;
import com.changhu.module.miniProgram.pojo.vo.ServiceProjectSecurityUserPagerVo;
import com.changhu.module.miniProgram.service.UserService;
import com.changhu.support.mybatisplus.pojo.params.PageParams;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 20252
 * @createTime 2024/9/6 上午10:42
 * @desc UserController...
 */
@Tag(name = "微信小程序-用户相关")
@JsonBody
@RequestMapping("/mp/user")
@RestController("miniProgramUserController")
public class UserController {

    @Autowired
    private UserService userService;

    @Operation(summary = "注册小程序用户")
    @PostMapping("/register")
    @IsWhiteList
    public void register(@RequestBody @Valid UserRegisterParams params) {
        userService.register(params);
    }

    @Operation(summary = "保存或更新保安人员")
    @PostMapping("/add_security_user_upd")
    public void saveOrUpdateSecurityUser(@RequestBody @Valid SecurityUserSaveOrUpdateParams params) {
        userService.saveOrUpdateSecurityUser(params);
    }

    @Operation(summary = "二维码表单录入保安人员")
    @PostMapping("/qrCodeFormInputSecurityUser")
    @IsWhiteList
    public void qrCodeFormInputSecurityUser(@RequestBody @Valid SecurityUserSaveOrUpdateParams params) {
        userService.qrCodeFormInputSecurityUser(params);
    }

    @Operation(summary = "服务项目保安人员分页")
    @PostMapping("/securityUserPager")
    public Page<ServiceProjectSecurityUserPagerVo> securityUserPager(@RequestBody PageParams<ServiceProjectSecurityUserPagerQueryParams, ServiceProjectSecurityUserPagerVo> queryParams) {
        return userService.securityUserPager(queryParams);
    }

    @Operation(summary = "根据id删除保安人员")
    @DeleteMapping("/del_security_user_id")
    public void deleteSecurityUserById(@RequestParam @Schema(description = "保安人员id") Long securityUserId) {
        userService.deleteSecurityUserById(securityUserId);
    }
}
