package server

import (
	"game/common/proto/pb"
	"github.com/fox/fox/log"
)

func (s *ClientService) reqLogin() {
	log.DebugF("user:%v ready reqLogin", s.username)
	s.SendMsg(pb.ServiceTypeId_STI_Login, int32(pb.MsgId_ReqUserLoginId), &pb.ReqUserLogin{
		Username: s.username,
		Password: s.password,
		Ip:       "",
		DeviceId: "",
		Version:  "20250604123030",
	})
}

// 收到登陆成功消息，判断是否顶号
func (s *ClientService) onLogin(cMsg *pb.ClientMsg, msg *pb.RspUserLogin) {
	if msg.Code != pb.ErrCode_OK {
		log.ErrorF("onLogin error:%v :%v", msg.Code, msg.Code.String())
		return
	}
	_ = cMsg
	s.userId = msg.UserId
	s.client.SetUid(msg.UserId)
	log.DebugF("user:%v id:%v reqLogin success", s.username, msg.UserId)
	s.reqMatchRoom()
}

// 收到登陆成功消息，判断是否顶号
func (s *ClientService) onLogout(cMsg *pb.ClientMsg, msg *pb.RspUserLogout) {
	if msg.Code != pb.ErrCode_OK {
		log.ErrorF("onLogout error:%v :%v", msg.Code, msg.Code.String())
		return
	}
	_ = cMsg
	log.DebugF("user:%v logout", s.userId)
}

func (s *ClientService) reqMatchRoom() {
	log.DebugF(s.Log("ready reqMatch"))
	s.SendMsg(pb.ServiceTypeId_STI_Match, int32(pb.MsgId_ReqMatchRoomId), &pb.ReqMatchRoom{
		GameId:   pb.ServiceTypeId_STI_ColorGame,
		RoomType: 0,
	})
}

func (s *ClientService) onMatchRoom(cMsg *pb.ClientMsg, msg *pb.RspMatchRoom) {
	if msg.Code != pb.ErrCode_OK {
		log.ErrorF("onMatch error:%v :%v", msg.Code, msg.Code.String())
		return
	}
	log.DebugF("user:%v onMatch success", s.userId)
	_ = cMsg
}

func (s *ClientService) onEnterRoom(cMsg *pb.ClientMsg, msg *pb.RspEnterRoom) {
	if msg.Code != pb.ErrCode_OK {
		log.ErrorF("onEnterRoom error:%v :%v", msg.Code, msg.Code.String())
		return
	}
	log.DebugF("user:%v onEnterRoom success", s.userId)
	_ = cMsg
}
