package main

import (
	//	"os"

	pb "common/rpc_world"

	"golang.org/x/net/context"
	"google.golang.org/grpc"
)

const (
	address = "localhost:50055"

//	address = "139.196.215.75:50055"

//	address = "139.196.215.75:50062"
)

func main() {
	conn, err := grpc.Dial(address, grpc.WithInsecure())
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	defer conn.Close()
	c := pb.NewRoomClient(conn)

	r, err := c.CreateRoom(context.Background(), &pb.CreateRoomRequest{RoomId: 100000, CreatePlayerId: 999, RoomName: "happyroom", RuleTimeLimit: 3600,
		SmallBlind: 2, BuyinMin: 3, PlayerCount: 5})
	if err != nil {
		log.Fatalf("could not CreateRoom: %v", err)
	}
	log.Printf("CreateRoom: %s", r.Message)

	r1, err1 := c.JoinRoom(context.Background(), &pb.JoinRoomRequest{RoomId: 100001, UserId: 999})
	if err1 != nil {
		log.Fatalf("could not JoinRoom: %v", err1)
	}
	log.Printf("CreateRoom: %s", r1.Message)

	ret, er := c.ModifyRoomInfo(context.Background(), &pb.ModifyRoomInfoRequest{Id: 100000, PlayerCount: 6})
	if er != nil {
		log.Fatalf("could not ModifyRoomInfo: %v", er)
	}
	log.Printf("ModifyRoomInfo: %s", ret.Message)

	rt, e := c.DestroyRoom(context.Background(), &pb.DestroyRoomRequest{Id: 100000})
	if e != nil {
		log.Fatalf("could not DestroyRoom: %v", e)
	}
	log.Printf("DestroyRoom: %s", rt.Message)

	rt1, e1 := c.GetNewRoomID(context.Background(), &pb.GetRoomIDRequest{Name: "阿明"})
	if e1 != nil {
		log.Fatalf("could not DestroyRoom: %v", e1)
	}
	log.Printf("GetNewRoomID: %s %d", rt1.RoomUuid, rt1.Roomid, "UuidInt:", rt1.UuidInt)

	rt2, e2 := c.CheckClubManager(context.Background(), &pb.CheckClubManagerRequest{Playerid: 100, Clubid: 1000})
	if e2 != nil {
		log.Fatalf("could not DestroyRoom: %v", e2)
	}
	log.Printf("CheckClubManager: %d", rt2.Result)

	rt3, e3 := c.CheckClubMember(context.Background(), &pb.CheckClubMemberRequest{Playerid: 10, Clubid: 10})
	if e3 != nil {
		log.Fatalf("could not DestroyRoom: %v", e3)
	}
	log.Printf("CheckClubMember: %d", rt3.Result)

}
