package com.palmnest.service;

import com.palmnest.application.bean.Page;
import com.palmnest.application.bean.Pagenation;
import com.palmnest.application.bean.RoleFloorTypeInfo;
import com.palmnest.application.dto.output.UserDataByTokenDto;
import com.palmnest.dao.UserDao;
import com.palmnest.model.*;
import com.palmnest.model.estateserve.VirtualAccount;
import org.hibernate.criterion.Criterion;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import scala.Int;

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

/**
 * Business Service Interface to handle communication between web and
 * persistence layer.
 *
 * @author <a href="mailto:chasel.java@gmail.com">Chasel Li</a>
 * @author yb
 * @since 2014-06-03
 */
public interface UserManager extends GenericManager<User, Long> {
	/**
	 * Convenience method for testing - allows you to mock the DAO and set it on
	 * an interface.
	 *
	 * @param userDao the UserDao implementation to use
	 */
	public void setUserDao(UserDao userDao);

	/**
	 * Retrieves a user by userId. An exception is thrown if user not found
	 *
	 * @param userId the identifier for the user
	 * @return User
	 */
	public User getUser(String userId);

	/**
	 * Finds a user by their username.
	 *
	 * @param username the user's username used to login
	 * @return User a populated user object
	 * @throws org.springframework.security.core.userdetails.UsernameNotFoundException exception thrown when user not found
	 */
	public User getUserByUsername(String username) throws UsernameNotFoundException;

	/**
	 * 获取用户 ad by yb
	 *
	 * @param username
	 * @return
	 */
	public User getUserByUsername2(String username);

	/**
	 * Retrieves a list of all users.
	 *
	 * @return List
	 */
	public List<User> getUsers();

	/**
	 * Saves a user's information.
	 *
	 * @param user the user's information
	 * @return user the updated user object
	 * @throws UserExistsException thrown when user already exists
	 */
	public User saveUser(User user) throws UserExistsException;

	/**
	 * 保存用户 add by yb
	 *
	 * @param user
	 * @return
	 */
	public void saveUser2(User user);

	public void updateUser(User user);

	/**
	 * 更新密码
	 *
	 * @param username
	 * @param oldPwd
	 * @param newPwd
	 */
	public boolean updateUserPwd(String username, String oldPwd, String newPwd);

	/**
	 * Removes a user from the database
	 *
	 * @param user the user to remove
	 */
	public void removeUser(User user);

	/**
	 * Removes a user from the database by their userId
	 *
	 * @param userId the user's id
	 */
	public void removeUser(String userId);

	/**
	 * Search a user for search terms.
	 *
	 * @param searchTerm the search terms.
	 * @return a list of matches, or all if no searchTerm.
	 */
	public List<User> search(String searchTerm);

	/**
	 * @param pageNo
	 * @param filterList
	 * @return
	 */
	public Pagenation<User> queryUser(int pageNo, List<Criterion> filterList);

	/**
	 * 分页查询
	 *
	 * @param pageNo   当前页数
	 * @param username 查询用户名(条件)
	 * @param roleId   角色条件
	 * @return
	 */
	public Page queryUser(int pageNo, int pageSize, String username, User user, String orgIds, String roleId);

	/**
	 * 查询用户（根据用户名和密码）
	 *
	 * @param username 用户名
	 * @param password 密码
	 * @return
	 */
	public User getUser(String username, String password);

	/**
	 * 查询用户组织管理集合
	 *
	 * @param userid
	 * @return
	 */
	public List<AppUserOrgnizationRelation> getAppUserOrgByUserId(int userid);

	/**查询用户组织管理集合
	 * @param userid
	 * @return
	 */
//	public List<AppUserOrgRelation> getAppUserOrgByUserId(int userid);

	/**
	 * 查询用户-运营中心管理集合
	 *
	 * @param userid
	 * @return
	 */
	public List<AppUserCompanyRelation> getAppUserCompanyByUserId(int userid);

	/**
	 * 查询用户项目管理集合
	 *
	 * @param userid
	 * @return
	 */
	public List<AppUserOrgnizationRelation> getUserOrgByUserId(Long userid);

	/**
	 * 查询用户所有楼宇楼层关系
	 *
	 * @param userid
	 * @return
	 */
	public List<AppUserFloorRelation> getAppUserFloorByUserId(int userid);

	/**
	 * 查询用户所有楼宇楼层关系
	 *
	 * @param userid
	 * @return
	 */
	public List<AppUserFloorRelation> getAppUserFloorByUserId(int userid, int roleId);

	/**查询用户组织管理集合
	 * @param userid
	 * @return
	 */
//	public List<AppUserOrgRelation> getAppUserOrgByUserId(int userid,String type);

	/**
	 * 删除用户组织表管理信息
	 * @param userid
	 * @param orgType
	 */
//	public void deleteAppUserOrgByUserId(int userid,String orgType);

	/**
	 * 删除用户项目管辖关系表信息
	 *
	 * @param userid
	 */
	public void deleteAppUserOrgByUserId(Long userid);

	public void deleteAppUserFloorByUserId(int userid, String orgType);

	/**
	 * 保存系统用户-小区关联
	 * @param user
	 * @param organizationId
	 * @return
	 */
//	public AppUserOrgRelation saveAppUserOrgRelation(User user,int organizationId);

	/**
	 * 后台保存更新系统更新通知时更新后台用户通知状态
	 */
	public void updateAllState();

	List<User> findByFunction(String systemCode);

	/**
	 * 新增/更新用户信息
	 * @param user 用户
	 * @param company 公司集合
	 * @param dept 部门集合
	 * @return
	 */
//	public String saveOrUpdateUser(User user,List<String> company,List<String> dept);

	/**
	 * 新增/更新用户信息
	 * 用户管辖项目
	 *
	 * @param user        用户
	 * @param orgnization 项目集合
	 * @return
	 */
	public String saveOrUpdateUser(User user, List<String> orgnization);

	/**
	 * 新增/更新用户信息
	 *
	 * @param user    用户
	 * @param company 公司集合
	 * @param dept    部门集合
	 * @return
	 */
//	public String saveOrUpdateUser(User user,List<String> company,List<String> dept,List<String> organization,List<String> floor);

//	public String getUser(User user,List<String> company,List<String> dept,List<String> organization,List<String> floor);
	public ArrayList<User> getUserByType(int type);

	List<User> findByFunction(Integer orgId, String systemCode);

	List<User> findByFunctionGeneral(Integer orgId, String systemCode);

	List<User> findByRoleId(Integer roleId, Integer orgId);

	User findByTelephone(String telephone);

	List<User> queryUserBySql(String querySql);

	/**
	 * 重置密码
	 *
	 * @param username
	 * @param newPwd
	 */
	public boolean resetUserPwd(String username, String newPwd);

	public String setUserRoleInfo(User userInfo, Map<String, RoleFloorTypeInfo> roleList, String roles, String user);

	public User findByFunctionAndUser(String systemCode, Long userId);

	public List<User> findByFunctionAndUserList(String systemCode, Long userId);

	public List<Map<String, Object>> findMeetingAuditRoleByOrdId(String OrdId);

	public UserDataByTokenDto setUserData(String userName);

	//根据systemCode 和  roleId 获得对应用户 和 floor_id
	List<User> findByFunAndRoleAndFloor(String systemCode, String floorId);

	public Role findRoleByFunctionAndUser(String systemCode, Long userId);

	//根据 systemCode roleIds 查符合条件的角色
	List<Role> findRoleBySystemCodeAndRoleIds(String systemCode, String roleIds);

	public void visitMeetingUrl(String userName);

	List<Map<String, Object>> getPower(String orgId, int sysCode);

	List<Map<String, Object>> getPowerByOrgIds(String orgIds, int sysCode);

	User createVirAccountUser(VirtualAccount virAccount);
}
