package config

import (
	"Wine-Server/handlers/manager/super/config/advertise"
	"Wine-Server/handlers/manager/super/config/device"
	"Wine-Server/handlers/manager/super/config/param"
	"Wine-Server/handlers/manager/super/config/wine"
	"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 {
	// device:
	case "superConfigDeviceQueryManager":
		device.QueryManager(conn, manager, msg.Data)
		break
	case "superConfigDeviceQuery":
		device.Query(conn, manager, msg.Data)
		break
	case "superConfigDeviceUpdate":
		device.Update(conn, manager, msg.Data)
		break
	case "superConfigDeviceAssign":
		device.Assign(conn, manager, msg.Data)
		break
	// wine:
	case "superConfigWineQuery":
		wine.Query(conn, manager, msg.Data)
		break
	case "superConfigWineDelete":
		wine.Delete(conn, manager, msg.Data)
		break
	case "superConfigWineAdd":
		wine.Add(conn, manager, msg.Data)
		break
	case "superConfigWineUpdate":
		wine.Update(conn, manager, msg.Data)
		break
	// advertise:
	case "superConfigAdvertiseQuery":
		advertise.Query(conn, manager, msg.Data)
		break
	case "superConfigAdvertiseDelete":
		advertise.Delete(conn, manager, msg.Data)
		break
	case "superConfigAdvertiseUpdate":
		advertise.Update(conn, manager, msg.Data)
		break
	case "superConfigAdvertiseAdd":
		advertise.Add(conn, manager, msg.Data)
		break
	// param:
	case "superConfigParamList":
		param.List(conn, manager, msg.Data)
		break
	case "superConfigParamUpdate":
		param.Update(conn, manager, msg.Data)
		break
	default:
		_ = conn.WriteJSON(utils.WsError("unrecognized event"))
		break
	}
}
