#pragma once

#include <QWidget>
#include <QTableWidgetItem>
#include "csqliteauthoritymanager.h"
#include "cpermissioninfo.h"
namespace Ui { class CMWAuthorityUser; };

class CMWAuthorityUser : public QWidget, public IAuthoritySupport
{
	Q_OBJECT

public:
	CMWAuthorityUser(QWidget *parent = Q_NULLPTR);
	~CMWAuthorityUser();

	int init();
	void FreshUser();
	void FreshRole();
	void FreshRoleState();
	void FreshSelectedUser();
	void user_itemChanged(QTableWidgetItem *item);
	void user_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn);

	void SetAuthorityManager(IAuthorityManager* instance) override;


	void FreshAuthority() override;

	private slots:
	void on_btnRefresh_clicked();
	void on_btnDel_clicked();
	void on_btnAdd_clicked();
	void on_btnModify_clicked();
	void on_btnDisable_clicked();
	void on_btnModifyRole_clicked();

	void SetControlPermission(QWidget* object, const PermissionInfo& permissionInfo);
private:
	std::map<QWidget*, PermissionInfo> m_mapObjectsPermission;

private:
	Ui::CMWAuthorityUser *ui;
	CSqliteAuthorityManager* m_AuthorityManager;
	QSqlDatabase m_db;
	QSqlTableModel* m_ModelUser;
	int m_iLastUserSelRow = -1;
	int m_iSelUserId = -1;

	// 通过 IAuthoritySupport 继承
	void InitAuthority() override;
};
