package internal

import (
	"reflect"
	"server/events"
	"server/msg"

	"github.com/name5566/leaf/gate"
	"github.com/name5566/leaf/log"
)

func handleMsg(m interface{}, h interface{}) {
	skeleton.RegisterChanRPC(reflect.TypeOf(m), h)
}

// 大厅有进入大厅，离开大厅，加入房间，玩法列表，商城
func init() {
	handleMsg(&msg.EnterHall{}, enterHallHandler)
	handleMsg(&msg.LeaveHall{}, leaveHallHandler)
	handleMsg(&msg.ResJoinRoom{}, joinRoomHandler)
	handleMsg(&msg.PlayList{}, playListHandler)
	handleMsg(&msg.Shop{}, shopHandler)
	handleMsg(&msg.ResGameInfo{}, reqGameInfoHandler)
	handleMsg(&msg.ResRoomID{}, reqRoomIdHandler)
	handleMsg(&msg.ReqLeaveRoom{}, leaveTeenPattiRoomHandler)
}
func reqRoomIdHandler(args []interface{}) {
	m := args[0].(*msg.ResRoomID)
	a := args[1].(gate.Agent)
	// log.Debug("reqGameInfoHandler, msg: %v, agent: %v", m, a)
	log.Debug("reqRoomIdHandler, msg: %+v, agent: %+v", m, a)
	switch m.GameId {
	case "teen_patti":
		events.EventChan <- events.Event{
			Type:  events.EventGetTeenPattiRoomId,
			Data:  m,
			Agent: a,
		}
	}
}
func leaveTeenPattiRoomHandler(args []interface{}) {
	m := args[0].(*msg.ReqLeaveRoom)
	a := args[1].(gate.Agent)
	// log.Debug("reqGameInfoHandler, msg: %v, agent: %v", m, a)
	log.Debug("reqGameInfoHandler, msg: %+v, agent: %+v", m, a)
	switch m.GameId {
	case "teen_patti":
		events.EventChan <- events.Event{
			Type:  events.EventLeaveTeenPattiRoom,
			Data:  m,
			Agent: a,
		}
	}
}
func reqGameInfoHandler(args []interface{}) {
	m := args[0].(*msg.ResGameInfo)
	a := args[1].(gate.Agent)
	// log.Debug("reqGameInfoHandler, msg: %v, agent: %v", m, a)
	log.Debug("reqGameInfoHandler, msg: %+v, agent: %+v", m, a)
	switch m.GameId {
	case "teen_patti":
		events.EventChan <- events.Event{
			Type:  events.EventTeenPattiGameInfo,
			Data:  m,
			Agent: a,
		}
	}
}

func enterHallHandler(args []interface{}) {
	m := args[0].(*msg.EnterHall)
	a := args[1].(gate.Agent)
	log.Debug("enterHallHandler, msg: %v, agent: %v", m, a)
}

func leaveHallHandler(args []interface{}) {
	m := args[0].(*msg.LeaveHall)
	a := args[1].(gate.Agent)
	log.Debug("leaveHallHandler, msg: %v, agent: %v", m, a)
}

func joinRoomHandler(args []interface{}) {
	m := args[0].(*msg.ResJoinRoom)
	a := args[1].(gate.Agent)
	switch m.GameId {
	case "teen_patti":
		events.EventChan <- events.Event{
			Type:  events.EventJoinTeenPattiRoom,
			Data:  m,
			Agent: a,
		}
	}
	log.Debug("joinRoomHandler, msg: %v, agent: %v", m, a)
}

func playListHandler(args []interface{}) {
	log.Debug("playListHandler")
}

func shopHandler(args []interface{}) {
	log.Debug("shopHandler")
}
