package worker

import (
	"Wine-Server/utils"
	"github.com/gorilla/websocket"
)

type openParam struct {
	Seq  string `json:"seq"`
	Kind string `json:"kind"`
}

func openGate(conn *websocket.Conn, wid string, data any) {
	var param openParam
	err := utils.AnyTrans(data, &param)
	if err != nil {
		_ = conn.WriteJSON(utils.WsError("params error"))
		return
	}
	if device, exist := utils.SellerDevices[param.Seq]; exist {
		if device.Online {
			_ = device.Conn.WriteJSON(utils.WsEvent("openGate", utils.JsonType{
				"kind":   param.Kind,
				"worker": wid,
			}))
			return
		}
		_ = conn.WriteJSON(utils.WsError("device offline"))
		return
	}
	_ = conn.WriteJSON(utils.WsError("no such device"))
}

func orderFinished(conn *websocket.Conn, obj any) {
	//
}
