package game

import (
	"fmt"
	"net/http"
	"server/conf"

	// "server/msg"

	"github.com/gorilla/mux"
)

type HttpManager struct {
	Rounter *mux.Router
}

func (p *HttpManager) InitRounter() {
	p.Rounter = mux.NewRouter()
	p.InitFriendRouter()
	p.InitPlayerProfileInfo()
	http.ListenAndServe(conf.Server.HttpPort, p.Rounter)
}

func (p *HttpManager) InitFriendRouter() {
	bs := p.Rounter.PathPrefix("/Friend").Subrouter()
	bs.HandleFunc("/Add/{SenderId}/{ReceiveId}", p.AddFriend)
	bs.HandleFunc("/Del/{SenderId}/{ReceiveId}", p.DeleteFriend)
}

func (p *HttpManager) InitPlayerProfileInfo() {
	bs := p.Rounter.PathPrefix("/Profile").Subrouter()
	bs.HandleFunc("/GetBrief/{Id}", p.GetPlayerProfileInfo)
}

func (p *HttpManager) GetPlayerProfileInfo(w http.ResponseWriter, r *http.Request) {

}

func (p *HttpManager) AddFriend(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	SenderId, ok := vars["SenderId"]
	if ok {
		fmt.Println("AddFreind SenderId:" + SenderId)
	}

	ReceiveId, ok1 := vars["ReceiveId"]
	if ok1 {
		fmt.Println("AddFreind ReceiveId:" + ReceiveId)
	}
}

func (p *HttpManager) DeleteFriend(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	id, ok := vars["id"]
	if !ok {
		fmt.Println("id is missing in parameters")
	}
	fmt.Println(`id := `, id)

}
