package wine

import (
	"Wine-Server/handlers/manager/admin/wine/change"
	"Wine-Server/handlers/manager/admin/wine/history"
	"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 {
	// change
	case "adminWineChangeQuery":
		change.Query(conn, manager, msg.Data)
		break
	case "adminWineChangeQueryWine":
		change.QueryWine(conn, msg.Data)
		break
	case "adminWineChangeQueryWorker":
		change.QueryWorker(conn, manager, msg.Data)
		break
	case "adminWineChangeAssign":
		change.Assign(conn, msg.Data)
		break
	// history
	case "adminWineHistoryQueryWorker":
		history.QueryWorker(conn, manager, msg.Data)
		break
	case "adminWineHistoryQueryOrder":
		history.QueryOrder(conn, manager, msg.Data)
		break
	case "adminWineHistoryOrderUpdate":
		history.OrderUpdate(conn, msg.Data)
		break
	case "adminWineHistoryOrderDelete":
		history.OrderDelete(conn, msg.Data)
		break
	default:
		_ = conn.WriteJSON(utils.WsError("unrecognized event"))
		break
	}
}
