package config

import (
	"Wine-Server/handlers/manager/super/role/admin"
	"Wine-Server/handlers/manager/super/role/worker"
	"Wine-Server/utils"
	"Wine-Server/utils/tables"
	"github.com/gorilla/websocket"
)

func Handle(msg utils.WsMsg, conn *websocket.Conn, manager *tables.ManagerTable) {
	switch msg.Event {
	// admin:
	case "superRoleAdminQuery":
		admin.Query(conn, manager, msg.Data)
		break
	case "superRoleAdminUpdate":
		admin.Update(conn, manager, msg.Data)
		break
	case "superRoleAdminDelete":
		admin.Delete(conn, manager, msg.Data)
		break
	case "superRoleAdminAdd":
		admin.Add(conn, manager, msg.Data)
		break
	// worker:
	case "superRoleWorkerQuery":
		worker.Query(conn, manager, msg.Data)
		break
	default:
		_ = conn.WriteJSON(utils.WsError("unrecognized event"))
		break
	}
}
