package main

import (
	"../gameapi"
	"../log"
	"./executor"
	"go.uber.org/zap"
	"strconv"
)
//夺宝电子 棋牌延时下分任务
// 1、JDB官方给的延时时间为15-30秒可以下分成功
// 2、策略: delay 8秒 开始下分 直到返回下分成功为止
// 3、在下分期间,用户可能会产生再次进入游戏的请求,返回禁止进入游戏并返回提示
// 4、适用于强制关端还有未完的牌局

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

type Executor_DBDZ struct {
	cmd string
}

func (self *Executor_DBDZ) 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.DBDZ_QP_withdraw(guid_str)
		if ok {
			newBanlance := gameapi.SettlementAndNtfToNats("DBDZ",guid_uint64, gameId_int64, with_money)
			log.Debug("Executor_DBDZ 任务执行成功",zap.String("guid",guid_str),zap.String("gameId",gameId_str))
			TaskPool.RemoveTasks(int64(guid_uint64))
			notifyClientByLobby(guid_uint64, newBanlance)
			gameapi.CleanReconnectInfo("DBDZ", guid_uint64)
			return  TASK_SUCCESS
		}else{
			log.Debug("Executor_DBDZ 任务执行失败",zap.String("guid",guid_str),zap.String("gameId",gameId_str))
			return  TASK_FAILED
		}
}

func NewExecutor_DBDZ(cmd string) executor.IExecutor {
	return &Executor_DBDZ{cmd:cmd}
}

func register_DBDZ() {
	executor.RegisterFunc("Executor_DBDZ", NewExecutor_DBDZ("withdraw"))
}

