/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.security.system.user.feign;


import org.security.common.constant.CommonConstant;
import org.security.system.user.entity.User;
import org.security.system.user.entity.UserDept;
import org.security.system.user.entity.UserInfo;
import org.security.system.user.entity.UserOauth;
import org.security.system.user.vo.UserVO;
import org.springblade.core.tool.api.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * User Feign接口类
 *
 * @author Chill
 */
@FeignClient(
	value = CommonConstant.APPLICATION_USER_NAME,
	fallback = UserClientFallback.class
)
public interface IUserClient {

	String API_PREFIX = "/client";
	String USER_INFO = API_PREFIX + "/user-info";
	String USER_INFO_BY_TYPE = API_PREFIX + "/user-info-by-type";
	String USER_INFO_BY_ID = API_PREFIX + "/user-info-by-id";
	String USER_INFO_BY_ACCOUNT = API_PREFIX + "/user-info-by-account";
	String USER_AUTH_INFO = API_PREFIX + "/user-auth-info";
	String SAVE_USER = API_PREFIX + "/save-user";
	String REMOVE_USER = API_PREFIX + "/remove-user";
	String USER_BY_CDOE = "/user/code";
	String HEAD_LEADERS = API_PREFIX + "/head-leaders";
	String HEAD_SEC_LEADERS = API_PREFIX + "/head-sec-leaders";
	String HEAD_SAFERS = API_PREFIX + "/head-safers";
	String BRANCH_LEADERS = API_PREFIX + "/branch-leaders";
	String SYN_REMOVE_USER_DEPT = API_PREFIX + "/syn/remove/data";
	String SYN_SAVE_USER_DEPT = API_PREFIX + "/syn/save/user-dept";
	String SYN_SAVE_USER_DATA = API_PREFIX + "/syn/save/user";
	String TASK_GET_USER_BYROLEID = API_PREFIX + "/task/getUser/byRoleId";
	String BRANCH_SAFERS = API_PREFIX + "/branch-safers";
	String SUB_LEADERS = API_PREFIX + "/sub-leaders";
	String SUB_SAFERS = API_PREFIX + "/sub-safers";
	String DEPT_LEADERS = API_PREFIX + "/dept-leaders";
	String HEAD_SEC_CENTER_ALL = API_PREFIX + "/head-sec-center-all";
	String BRANCH_SEC_CENTER_ALL = API_PREFIX + "/branch-sec-center-all";
	String USERS_BY_IDS = API_PREFIX + "/users-by-ids";
	String USER_HAS_ROLE_ALIAS = API_PREFIX + "/users-has-role-alias";

	/**
	 * 获取用户信息
	 *
	 * @param userId 用户id
	 * @return
	 */
	@GetMapping(USER_INFO_BY_ID)
	R<User> userInfoById(@RequestParam("userId") Long userId);


	/**
	 * 根据账号获取用户信息
	 *
	 * @param tenantId 租户id
	 * @param account  账号
	 * @return
	 */
	@GetMapping(USER_INFO_BY_ACCOUNT)
	R<User> userByAccount(@RequestParam("tenantId") String tenantId, @RequestParam("account") String account);

	/**
	 * 获取用户信息
	 *
	 * @param tenantId 租户ID
	 * @param account  账号
	 * @return
	 */
	@GetMapping(USER_INFO)
	R<UserInfo> userInfo(@RequestParam("tenantId") String tenantId, @RequestParam("account") String account);

	/**
	 * 获取用户信息
	 *
	 * @param tenantId 租户ID
	 * @param account  账号
	 * @param userType 用户平台
	 * @return
	 */
	@GetMapping(USER_INFO_BY_TYPE)
	R<UserInfo> userInfo(@RequestParam("tenantId") String tenantId, @RequestParam("account") String account, @RequestParam("userType") String userType);

	/**
	 * 获取第三方平台信息
	 *
	 * @param userOauth 第三方授权用户信息
	 * @return UserInfo
	 */
	@PostMapping(USER_AUTH_INFO)
	R<UserInfo> userAuthInfo(@RequestBody UserOauth userOauth);

	/**
	 * 新建用户
	 *
	 * @param user 用户实体
	 * @return
	 */
	@PostMapping(SAVE_USER)
	R saveUser(@RequestBody User user);

	/**
	 * 删除用户
	 *
	 * @param tenantIds 租户id集合
	 * @return
	 */
	@PostMapping(REMOVE_USER)
	R removeUser(@RequestParam("tenantIds") String tenantIds);

	/**
	 * 根据工号查询
	 * @param code
	 * @return
	 */
	@GetMapping(USER_BY_CDOE)
	R<UserVO> getUserByCode(@PathVariable String code);

	/**
	 * 获取用户所在总行领导
	 *
	 * @param userId 用户id
	 * @return
	 */
	@GetMapping(HEAD_LEADERS)
	R<List<UserVO>> headLeaders(@RequestParam("userId") Long userId);

	/**
	 * 获取用户所在总行安全部领导
	 *
	 * @param userId 用户id
	 * @return
	 */
	@GetMapping(HEAD_SEC_LEADERS)
	R<List<UserVO>> headSecLeaders(@RequestParam("userId") Long userId);

	/**
	 * 获取用户所在总行安全员
	 *
	 * @param userId 用户id
	 * @return
	 */
	@GetMapping(HEAD_SAFERS)
	R<List<UserVO>> headSafers(@RequestParam("userId") Long userId);

	/**
	 * 获取用户所在分行领导
	 *
	 * @param userId 用户id
	 * @return
	 */
	@GetMapping(BRANCH_LEADERS)
	R<List<UserVO>> branchLeaders(@RequestParam("userId") Long userId);

	/**
	 * 获取用户所在分行安全员
	 *
	 * @param userId 用户id
	 * @return
	 */
	@GetMapping(BRANCH_SAFERS)
	R<List<UserVO>> branchSafers(@RequestParam("userId") Long userId);

	/**
	 * 获取用户所在支行领导
	 *
	 * @param userId 用户id
	 * @return
	 */
	@GetMapping(SUB_LEADERS)
	R<List<UserVO>> subLeaders(@RequestParam("userId") Long userId);

	/**
	 * 获取用户所在支行安全员
	 *
	 * @param userId 用户id
	 * @return
	 */
	@GetMapping(SUB_SAFERS)
	R<List<UserVO>> subSafers(@RequestParam("userId") Long userId);

	/**
	 * 获取用户所在部门领导
	 *
	 * @param userId 用户id
	 * @return
	 */
	@GetMapping(DEPT_LEADERS)
	R<List<UserVO>> deptLeaders(@RequestParam("userId") Long userId);

	/**
	 * 总行安保指挥中心全员
	 *
	 * @return
	 */
	@GetMapping(HEAD_SEC_CENTER_ALL)
	R<List<UserVO>> headSecCenterAll();

	/**
	 * 分行安保指挥中心全员
	 *
	 * @return
	 */
	@GetMapping(BRANCH_SEC_CENTER_ALL)
	R<List<UserVO>> branchSecCenterAll();

	/**
	 * 消息总线同步消息前移除blade_user_dept表中冗余关系数据
	 */
	@PostMapping(SYN_REMOVE_USER_DEPT)
	R removeUserDept(@RequestParam List<String> userIds);


	/**
	 * 消息总线同步消息添加blade_user_dept关联信息
	 */
	@PostMapping(SYN_SAVE_USER_DEPT)
	R saveUserDept(@RequestBody List<UserDept> userDeptList);

	/**
	 * 消息总线信息同步blade_user表信息更新
	 */
	@PostMapping(SYN_SAVE_USER_DATA)
	R saveUserData(@RequestBody List<User> userList);

	/**
	 *定时任务根据角色id获取用户
	 */
	@GetMapping(TASK_GET_USER_BYROLEID)
	R<List<UserVO>> getUserByRoleId (@RequestParam String roleId);

	/**
	 * 根据用户id获取用户列表
	 */
	@GetMapping(USERS_BY_IDS)
	R getUsersByUserIds (@RequestParam String userIds);

	@GetMapping(USER_HAS_ROLE_ALIAS)
	R userHasRoleAlias (@RequestParam String tenantId, @RequestParam Long userId, @RequestParam String roleAlias);
}
