package com.changhu.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.changhu.common.annotation.CheckUserType;
import com.changhu.common.annotation.IsWhiteList;
import com.changhu.common.annotation.JsonBody;
import com.changhu.common.db.enums.MiniProgramUserIdentity;
import com.changhu.common.db.enums.UserType;
import com.changhu.common.pojo.vo.SelectNodeVo;
import com.changhu.pojo.params.CheckStatusParams;
import com.changhu.pojo.params.UnitDisableOrEnableParams;
import com.changhu.pojo.vo.UnitCheckStatusVo;
import com.changhu.pojo.vo.UnitMiniProgramUserPagerQueryParams;
import com.changhu.pojo.vo.UnitMiniProgramUserPagerVo;
import com.changhu.service.ManagementService;
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/11/22 上午9:03
 * @desc ManagementController...
 */
@Tag(name = "后台-通用接口")
@JsonBody
@RequestMapping("/management")
@RestController
public class ManagementController {
    @Autowired
    private ManagementService managementService;

    @Operation(summary = "获取审核状态")
    @PostMapping("/getCheckStatus")
    @IsWhiteList
    public UnitCheckStatusVo getCheckStatus(@RequestBody @Valid CheckStatusParams params) {
        return managementService.getCheckStatus(params);
    }

    @Operation(summary = "查询单位下的小程序用户")
    @PostMapping("/miniProgramUserPager")
    @CheckUserType(userTypes = {UserType.MANAGEMENT_POLICE, UserType.MANAGEMENT_SECURITY})
    public Page<UnitMiniProgramUserPagerVo> miniProgramUserPager(@RequestBody PageParams<UnitMiniProgramUserPagerQueryParams, UnitMiniProgramUserPagerVo> queryParams) {
        return managementService.miniProgramUserPager(queryParams);
    }

    @Operation(summary = "审核通过小程序用户")
    @PostMapping("/passMiniProgramUser")
    @CheckUserType(userTypes = {UserType.MANAGEMENT_POLICE, UserType.MANAGEMENT_SECURITY})
    public void passMiniProgramUser(@RequestBody @Valid UnitDisableOrEnableParams params) {
        managementService.passMiniProgramUser(params);
    }

    @Operation(summary = "禁用或启用小程序用户")
    @PostMapping("/disableOrEnableMiniProgramUser")
    @CheckUserType(userTypes = {UserType.MANAGEMENT_POLICE, UserType.MANAGEMENT_SECURITY})
    public void disableOrEnableMiniProgramUser(@RequestBody @Valid UnitDisableOrEnableParams params) {
        managementService.disableOrEnableMiniProgramUser(params);
    }

    @Operation(summary = "所有的保安单位列表")
    @GetMapping("/listSecurityUnit")
    public List<SelectNodeVo<Long>> listSecurityUnit() {
        return managementService.listSecurityUnit();
    }

    @Operation(summary = "保安单位下的项目经理")
    @GetMapping("/listMinUserByUnitId")
    public List<SelectNodeVo<Long>> listMinUserByUnitId(@RequestParam @Schema(description = "保安单位id") Long securityUnitId,
                                                        @RequestParam @Schema(description = "身份类型") MiniProgramUserIdentity identity) {
        return managementService.listMinUserByUnitId(securityUnitId, identity);
    }
}
