package jnpf.authority.controller;

import io.swagger.v3.oas.annotations.Operation;
import jnpf.authority.service.FtbPermissionUsersService;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.model.authority.dto.permission.AuthGetTargetUserInfoBatchDTO;
import jnpf.permission.dto.v2.user.QueryPageUserDTO;
import jnpf.permission.dto.v2.user.QueryPageUserMoreKeywordDTO;
import jnpf.permission.eum.v2.UserWorkStatusEnums;
import jnpf.permission.model.ListIdDTO;
import jnpf.permission.vo.v2.user.UserBoundVO;
import jnpf.util.NoDataSourceBind;
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-21
 */
@RestController
@RequestMapping("/permission/users")
@Slf4j
public class FtbPermissionUsersController {

    @Resource
    private FtbPermissionUsersService ftbPermissionUsersService;

    @Operation(summary = "[分页] 在职人员列表")
    @PostMapping("/page")
    @NoDataSourceBind
    public ActionResult<PageListVO<UserBoundVO>> pagePost(@RequestBody QueryPageUserDTO dto) {
        return ActionResult.success(ftbPermissionUsersService.pagePost(dto));
    }

    @Operation(summary = "[分页] 在职人员列表POST更多关键字信息")
    @PostMapping("/page/moreKeyword")
    @NoDataSourceBind
    public ActionResult<PageListVO<UserBoundVO>> pagePostMoreKeyword(@RequestBody QueryPageUserMoreKeywordDTO dto) {
        return ActionResult.success(ftbPermissionUsersService.pagePostMoreKeyword(dto));
    }

    @Operation(summary = "[列表]权限过滤,获取所有用户信息,含绑定关系,或指定用户. 不使用权限则返回全部")
    @PostMapping("/info/all/auth")
    @NoDataSourceBind
    public ActionResult<List<UserBoundVO>> authGetAllUserInfoBatch() {
        return ActionResult.success(ftbPermissionUsersService.authGetAllUserInfoBatch());
    }

    @Operation(summary = "[列表]权限范围内仅返回用户 id 列表，不查关系与 VO")
    @PostMapping("/ids/auth")
    @NoDataSourceBind
    public ActionResult<List<String>> authGetPermissionScopeUserIds() {
        return ActionResult.success(ftbPermissionUsersService.authGetPermissionScopeUserIds());
    }

    @Operation(summary = "[列表] 指定组织下得所有员工信息(FTB带权限)")
    @GetMapping("/list/targetOrganize/auth")
    public ActionResult<List<UserBoundVO>> listTargetOrganizeIdAuth(@RequestParam(value = "organizeId") String organizeId) {
        return ActionResult.success(ftbPermissionUsersService.listTargetOrganizeIdAuth(organizeId, null));
    }

    @Operation(summary = "[列表] 指定组织下得所有员工信息(FTB带权限)")
    @GetMapping("/list/targetOrganize/auth/api")
    public List<UserBoundVO> listTargetOrganizeIdAuthApi(@RequestParam(value = "organizeId") String organizeId, @RequestParam(value = "userWorkStatusEnumsList", required = false) List<UserWorkStatusEnums> userWorkStatusEnumsList) {
        return ftbPermissionUsersService.listTargetOrganizeIdAuth(organizeId, userWorkStatusEnumsList);
    }

    @Operation(summary = "[列表] 指定组织集合下得所有员工信息(FTB带权限)")
    @PostMapping("/list/targetOrganizeIds/auth/api")
    public List<UserBoundVO> listTargetOrganizeIdsAuthApi(@RequestBody List<String> organizeIds, @RequestParam(value = "userWorkStatusEnumsList", required = false) List<UserWorkStatusEnums> userWorkStatusEnumsList) {
        return ftbPermissionUsersService.listTargetOrganizeIdsAuth(organizeIds, userWorkStatusEnumsList);
    }

    @Operation(summary = "[列表]权限过滤,获取指定id的用户信息,含绑定关系. 不使用权限则返回全部")
    @PostMapping("/info/targetUserIds/auth")
    public ActionResult<List<UserBoundVO>> authGetTargetUserInfoBatch(@RequestBody AuthGetTargetUserInfoBatchDTO dto) {
        return ActionResult.success(ftbPermissionUsersService.authGetTargetUserInfoBatch(dto));
    }

    @Operation(summary = "[列表含离职] 查询指定用户id的用户信息")
    @PostMapping("/info/targetUserIds")
    public ActionResult<List<UserBoundVO>> getTargetUserInfoBatchByIds(@RequestBody ListIdDTO dto) {
        return ActionResult.success(ftbPermissionUsersService.getTargetUserInfoBatchByIds(dto.getIds()));
    }
}
