package com.changhu.module.management.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.changhu.common.annotation.CheckUserType;
import com.changhu.common.annotation.JsonBody;
import com.changhu.common.db.enums.UserType;
import com.changhu.common.pojo.vo.SelectNodeVo;
import com.changhu.module.management.pojo.params.ManagementSecurityUnitUserSaveOrUpdateParams;
import com.changhu.module.management.pojo.queryParams.ManagementSecurityUnitUserPagerQueryParams;
import com.changhu.module.management.pojo.vo.ManagementSecurityUnitUserPagerVo;
import com.changhu.module.management.service.SecurityService;
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.*;

import java.util.List;

/**
 * @author 20252
 * @createTime 2024/9/11 上午9:39
 * @desc SecurityController...
 */
@Tag(name = "后台-保安")
@JsonBody
@RequestMapping("/management/security")
@CheckUserType(userTypes = UserType.MANAGEMENT_SECURITY)
public class SecurityController {

    @Autowired
    private SecurityService securityService;

    @Operation(summary = "新增或修改后台用户")
    @PostMapping("/user/saveOrUpdate")
    public void userSaveOrUpdate(@RequestBody @Valid ManagementSecurityUnitUserSaveOrUpdateParams saveOrUpdateParams) {
        securityService.userSaveOrUpdate(saveOrUpdateParams);
    }

    @Operation(summary = "分页查询后台用户")
    @PostMapping("/user/pager")
    public Page<ManagementSecurityUnitUserPagerVo> userPager(@RequestBody PageParams<ManagementSecurityUnitUserPagerQueryParams, ManagementSecurityUnitUserPagerVo> queryParams) {
        return securityService.userPager(queryParams);
    }

    @Operation(summary = "根据id删除后台用户")
    @DeleteMapping("/user/deleteById")
    public void userDeleteById(@RequestParam @Schema(description = "后台保安用户id") Long managementSecurityUnitUserId) {
        securityService.userDeleteById(managementSecurityUnitUserId);
    }

    @Operation(summary = "查询单位下的项目经理")
    @GetMapping("/listProjectManager")
    public List<SelectNodeVo<Long>> listProjectManager() {
        return securityService.listProjectManager();
    }
}
