package jnpf.authority.controller;

import io.swagger.v3.oas.annotations.Operation;
import jnpf.authority.service.FtbPermissionPositionService;
import jnpf.base.ActionResult;
import jnpf.model.authority.dto.permission.OrganizeWithPositionsDTO;
import jnpf.permission.eum.v2.UserWorkStatusEnums;
import jnpf.permission.vo.organize.OrganizeAndPositionListVO;
import jnpf.permission.vo.v2.position.PositionBaseInfoVO;
import jnpf.permission.vo.v2.position.PositionListOrganizeUserVO;
import jnpf.permission.vo.v2.position.PositionListUserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 带权限的岗位功能
 *
 * @author Flynn Chan
 * @create 2025-05-06
 */
@RestController
@RequestMapping("/permission/position")
@Slf4j
public class FtbPermissionPositionController {
    @Resource
    private FtbPermissionPositionService ftbPermissionPositionService;

    @Operation(summary = "[列表]人员权限过滤后的岗位用户列表")
    @GetMapping("/tree/users")
    public ActionResult<List<PositionListUserVO>> authListPositionTreeUser(@RequestParam(value = "filterUserWorkStatusEnumsList", required = false) List<UserWorkStatusEnums> filterUserWorkStatusEnumsList,
                                                                           @RequestParam(value = "includeResigned", required = false) Boolean includeResigned) {
        if (includeResigned == null) {
            includeResigned = false;
        }
        return ActionResult.success(ftbPermissionPositionService.authListPositionTreeUser(filterUserWorkStatusEnumsList, includeResigned));
    }

    @Operation(summary = "[列表]人员权限过滤后的岗位列表")
    @GetMapping("/list")
    public ActionResult<List<PositionBaseInfoVO>> authListPositionAuth() {
        return ActionResult.success(ftbPermissionPositionService.authListPositionAuth());
    }

    @Operation(summary = "[列表-含离职]全岗位挂组织再挂用户列表")
    @GetMapping("/List/organize/users")
    public ActionResult<List<PositionListOrganizeUserVO>> listPositionOrganizeUser(@RequestParam(value = "filterUserWorkStatusEnumsList", required = false) List<UserWorkStatusEnums> filterUserWorkStatusEnumsList) {
        return ActionResult.success(ftbPermissionPositionService.listPositionOrganizeUser(filterUserWorkStatusEnumsList));
    }

    @Operation(summary = "[api列表]权限范围内的多个组织及其岗位列表(不查人)")
    @PostMapping("/api/list/auth/organize-with-positions")
    public List<OrganizeAndPositionListVO> authOrganizeWithPositions(@RequestBody OrganizeWithPositionsDTO dto){
        return ftbPermissionPositionService.authOrganizeWithPositions(dto);
    }
}
