package jnpf.authority;

import io.swagger.v3.oas.annotations.Operation;
import jnpf.authority.fallback.FtbAuthorityApiFallback;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.model.authority.dto.menu.FunctionMenuRemoteDTO;
import jnpf.model.authority.dto.menu.FuntionMenuDTO;
import jnpf.model.authority.dto.permission.OrganizeWithPositionsDTO;
import jnpf.model.authority.dto.role.FtbPermissionRoleInfoDTO;
import jnpf.model.authority.vo.person.FtbRoleListDropDownVO;
import jnpf.model.authority.vo.role.FtbPermissionRoleIdentificationVO;
import jnpf.model.authority.vo.role.FtbPermissionRoleInfoVO;
import jnpf.model.cultivate.CultivatePage;
import jnpf.model.cultivate.vo.common.InnerPowerPositionVO;
import jnpf.model.cultivate.vo.common.InnerPowerUserVO;
import jnpf.model.login.MenuTreeVO;
import jnpf.permission.dto.v2.user.QueryPageUserDTO;
import jnpf.permission.dto.v2.user.QueryPageUserMoreKeywordDTO;
import jnpf.permission.eum.v2.OrganizeCategoryEnums;
import jnpf.permission.eum.v2.UserWorkStatusEnums;
import jnpf.permission.vo.organize.OrganizeAndPositionListVO;
import jnpf.permission.vo.store.StoreBaseListInfo;
import jnpf.permission.vo.v2.TargetAuthIdsVO;
import jnpf.permission.vo.v2.organzie.OrganizeGeneralDetailVO;
import jnpf.permission.vo.v2.organzie.OrganizeManagerFilterNodeVO;
import jnpf.permission.vo.v2.organzie.OrganizeManagerNodeVO;
import jnpf.permission.vo.v2.position.PositionListUserVO;
import jnpf.permission.vo.v2.user.UserBoundVO;
import jnpf.util.NoDataSourceBind;
import lombok.SneakyThrows;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: peng.hao
 * @create: 2025/3/27
 */
@FeignClient(name = "jnpf-ftb", fallbackFactory = FtbAuthorityApiFallback.class)
public interface FtbAuthorityApi {
    /**
     * 获取当前人员的数据权限范围
     *
     * @return
     */
    @GetMapping("/web/permission-role/query-user-scope-permission")
    Map<String, String> queryUserScopeOfPermission(@RequestParam("userId") String userId);

    @Operation(summary = "[门店基础信息列表auth api] 根据登录人权限得到权限范围内门店基础信息")
    @GetMapping(value = "/permission/organize/list/store/login")
    List<StoreBaseListInfo> authStoreBaseListInfo();

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

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

    @Operation(summary = "[分页] 在职人员列表")
    @PostMapping("/permission/users/page")
    @NoDataSourceBind
    ActionResult<PageListVO<UserBoundVO>> pagePost(@RequestBody QueryPageUserDTO dto);

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

    @Operation(summary = "[列表]人员权限过滤后的岗位用户列表")
    @GetMapping("/permission/position/tree/users")
    ActionResult<List<PositionListUserVO>> authListPositionTreeUser();

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

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

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

    @Operation(summary = "[树形]人员权限过滤后的组织(公司,部门,门店,班主),人员")
    @GetMapping(value = "/permission/organize/tree/users")
    ActionResult<List<OrganizeManagerNodeVO>> listOrganizeTreeUsers();

    @Operation(summary = "[列表]人员权限过滤后的组织列表")
    @GetMapping(value = "/permission/organize/info/list/users")
    @NoDataSourceBind
    ActionResult<List<OrganizeGeneralDetailVO>> authOrganizesByUserBound(@RequestParam(value = "organizeCategoryEnums", required = false) List<OrganizeCategoryEnums> organizeCategoryEnums);

    /**
     * @param organizeCategoryEnums 组织类型
     * @param workStatusEnums       工作状态
     * @param withEmployee          是否包含人员
     * @param filterBindOtherStore  过滤绑定第三方信息门店
     * @param filterBindPayStore    过滤收银平台门店
     * @return 组织树(with auth)
     */
    @Operation(summary = "[api树形,滤掉没有的分支]人员权限过滤后的组织(公司,部门,门店,班主),默认不带人员")
    @GetMapping(value = "/permission/organize/api/tree/users/filterNode")
    List<OrganizeManagerFilterNodeVO> listOrganizeTreeFilterNode(
            @RequestParam(value = "organizeCategoryEnums", required = false) List<OrganizeCategoryEnums> organizeCategoryEnums,
            @RequestParam(value = "workStatusEnums", required = false) List<UserWorkStatusEnums> workStatusEnums,
            @RequestParam(value = "withEmployee", required = false) Boolean withEmployee,
            @RequestParam(value = "filterBindOtherStore", required = false) Boolean filterBindOtherStore,
            @RequestParam(value = "filterBindPayStore", required = false) Boolean filterBindPayStore
    );

    @Operation(summary = "角色列表下拉")
    @GetMapping(value = "/web/permission-role-authorize-person/allRolesOfTheCurrentPerson")
    @NoDataSourceBind
    ActionResult<List<FtbRoleListDropDownVO>> roleListDropDown(@RequestParam("userId") String userId, @RequestParam("tenantId") String tenantId);

    /**
     * 根据模块编码获取当前人员的数据权限范围
     *
     * @return
     */
    @GetMapping("/web/permission-role/query-user-scope-permission-for-module-code")
    InnerPowerUserVO queryUserScopeOfPermissionForModuleCode();

    /**
     * 远程client
     * 包含新增修改
     */
    @SneakyThrows
    @PostMapping("/remoteClient")
    @NoDataSourceBind
    void remoteClient(FunctionMenuRemoteDTO dto);


    @GetMapping("/position/get-curr-login-user-has-permission-position-id")
    InnerPowerPositionVO getCurrLoginUserHasPermissionPositionId(@RequestParam(name = "permissionModule", defaultValue = "") String permissionModule);

    /**
     * 更具岗位id清除所有绑定的角色
     */
    @PostMapping("/web/permission-role-authorize-post/clearRoleByPostId")
    void clearRoleByPostId(@RequestBody List<String> postIds);

    /**
     * @param userIds 用户列表
     * @param status  状态 1：禁用 0：启用 -1-所有
     * @param tenantId 租户id
     * @return
     */
    @Operation(summary = "[列表]根据用户列表批量查询权限范围的门店")
    @PostMapping(value = "/permission/organize/batchForUserIds/{status}/{moduleId}/{tenantId}")
    @NoDataSourceBind
    Map<String, List<String>> batchAuthOrganizesForUserIdsAndTenantId(@RequestBody List<String> userIds, @PathVariable("status") Integer status,@PathVariable("moduleId") String moduleId,@PathVariable("tenantId") String tenantId);
/**
     * @param userIds 用户列表
     * @param status  状态 1：禁用 0：启用 -1-所有
     * @param tenantId 租户id
     * @return
     */
    @Operation(summary = "[列表]根据用户列表批量查询权限范围的门店")
    @PostMapping(value = "/permission/organize/batchAllForUserIds/{status}/{moduleId}/{tenantId}")
    @NoDataSourceBind
    Map<String, List<String>> batchAuthOrganizesAllForUserIdsAndTenantId(@RequestBody List<String> userIds, @PathVariable("status") Integer status,@PathVariable("moduleId") String moduleId,@PathVariable("tenantId") String tenantId);

    /**
     * @param userIds 用户列表
     * @param status  状态 1：禁用 0：启用 -1-所有
     * @return
     */
    @Operation(summary = "[列表]根据用户列表批量查询权限范围的门店")
    @PostMapping(value = "/permission/organize/batchForUserIds/{status}")
    Map<String, List<String>> batchAuthOrganizesForUserIds(@RequestBody List<String> userIds, @PathVariable("status") Integer status);


    /**
     * 角色列表
     *
     * @return {@link ActionResult }<{@link PageListVO }<{@link FtbPermissionRoleInfoVO }>>
     */
    @GetMapping("/web/permission-role/role-list")
    ActionResult<PageListVO<FtbPermissionRoleInfoVO>> permissionList(@SpringQueryMap CultivatePage cultivatePage, @SpringQueryMap FtbPermissionRoleInfoDTO roleInfoDTO);

    /**
     * 当前登录用户所有权限用户id
     *
     * @return 用户id集合
     */
    @GetMapping("/web/permission-role-authorize-person/permission-user")
    ActionResult<List<String>> permissionUser(@RequestParam("userId") String userId, @RequestParam("permissionModule") String permissionModule, @RequestParam("category") String category);

    /**
     * 员工已有的功能权限标识集合
     */
    @GetMapping("/web/permission-role/permission-identification-collection")
    ActionResult<FtbPermissionRoleIdentificationVO> permissionIdentificationCollection();

    /**
     * 查询那些人员具有当前按钮权限
     */
    @PostMapping("/web/permission-role-authorize-person/queryButtonPermission")
    List<String> queryButtonPermission(@RequestBody FuntionMenuDTO funtion);

    /**
     * 根据用户Id获取用户权限的用户Id集合（超级管理员不要调用此方法）
     * @return 用户id->所具有的权限用户id集合
     */
    @PostMapping("/web/permission-role-authorize-person/collection-of-user")
    Map<String,List<String>> getUserPermissionUserCollection(@RequestBody List<String> userIds);

    @GetMapping(value = "/permission/organize/user-auth")
    TargetAuthIdsVO getUserAuth();
    /**
     * 当前登录用户菜单树（与 FTB 登录菜单一致；type=Web|App）
     */
    @GetMapping("/web/permission-role/obtain-menus-on-token")
    ActionResult<List<MenuTreeVO>> obtainMenusOnToken(@RequestParam(value = "type", defaultValue = "Web") String type);

}
