#ifndef IAUTHORITYMANAGER_H
#define IAUTHORITYMANAGER_H
#include <string>
#include <vector>
#include <map>
#include "authorityentity.h"
class IAuthorityProvider {
public:
	virtual std::string GetPermissionTag(int iPermissionId) = 0;
	virtual int GetPermissionId(std::string sPermissionTag) = 0;
	virtual bool HasPermission(int iPermissionId) = 0;
	virtual bool HasPermission(std::string sPermissionTag) = 0;
	virtual bool HasPermission(std::vector<std::string> vecPermissionList) = 0;
	virtual std::map<int, std::string> GetPermissionList() = 0;

public:
	virtual bool Login(const std::string loginName, const std::string password) = 0;
	virtual bool HasLogin() = 0;
	virtual User GetLoginUser() = 0;
	std::function<void()> LoginUserChanged = nullptr;

	virtual std::string GetLastError() = 0;
};

class IAuthorityEntityManager {
public:
	virtual std::map<int, User> GetUsers(bool bAll) = 0;
	virtual std::map<int, Role> GetRoles() = 0;
	virtual std::map<int, Permission> GetPermissions() = 0;

	virtual bool AddUser(const User& user) = 0;
	virtual bool DeleteUser(int userId, bool bSetTag) = 0;
	virtual bool DeleteUser(const std::string loginName) = 0;
	virtual bool EnableUser(int userId, bool bEnable) = 0;
	virtual bool MotifyUser(const User& user, bool bPassword = false) = 0;

	virtual bool AddRole(const Role& role) = 0;
	virtual bool DeleteRole(int roleId) = 0;
	virtual bool MotifyRole(const Role& role) = 0;

	virtual bool AddPermission(const Permission& permission) = 0;
	virtual bool DeletePermission(int permissionId) = 0;
	virtual bool MotifyPermission(const Permission& permission) = 0;

	virtual std::map<int, Permission> GetPermissionsByUser(int userId) = 0;
	virtual std::map<int, int> GetRolesByUser(int userId) = 0;
	virtual bool UpdateUserRoles(int userId, std::vector<int> roleIdList) = 0;
	virtual bool UpdateRolePermissions(int roleId, std::vector<int> permissionIdList) = 0;
};

class IAuthorityManager : public IAuthorityProvider, IAuthorityEntityManager {

};

class IAuthoritySupport {
public:
	virtual	void SetAuthorityManager(IAuthorityManager* instance)
	{
		m_AuthorityInstance = instance;
	}
	/**
	 * @brief 刷新权限界面或控制.
	 * 
	 */
	virtual void FreshAuthority() = 0;

	/**
	 * @brief 初始化权限配置.
	 * 
	 */
	virtual void InitAuthority() = 0;
protected:
	IAuthorityManager* m_AuthorityInstance = nullptr;
};
#endif // IAUTHORITYMANAGER_H