package main

import (
	"../gameapi"
	"../log"
	"./executor"
	"go.uber.org/zap"
	"strconv"
)
//ig适用于强制关端还有未完的牌局

type IG_param struct {
	Guid string `json:"guid"`
	GameId string `json:"gameId"`
}

type Executor_IG struct {
	cmd string
}

func (self *Executor_IG) Execute(p interface{}) int32 {
	guid_uint64   := uint64(p.(map[string]interface{})["guid"].(float64))
	gameId_int64  := int64(p.(map[string]interface{})["gameId"].(float64))

	guid_str := strconv.FormatUint(guid_uint64,10)
	gameId_str := strconv.FormatInt(gameId_int64,10)

	with_money, ok := gameapi.IG_withdraw(guid_str)
	if ok {
		newBanlance := gameapi.SettlementAndNtfToNats("IG",guid_uint64, gameId_int64, with_money)
		log.Debug("Executor_IG 任务执行成功",zap.String("guid",guid_str),zap.String("gameId", gameId_str))
		TaskPool.RemoveTasks(int64(guid_uint64))
		notifyClientByLobby(guid_uint64, newBanlance)
		gameapi.CleanReconnectInfo("IG", guid_uint64)
		return  TASK_SUCCESS
	}else{
		log.Debug("Executor_IG 任务执行失败",zap.String("guid",guid_str),zap.String("gameId", gameId_str))
		return  TASK_FAILED
	}
}

func NewExecutor_IG(cmd string) executor.IExecutor {
	return &Executor_IG{cmd:cmd}
}

func register_IG() {
	executor.RegisterFunc("Executor_IG", NewExecutor_IG("withdraw"))
}