package com.evt.mgr;

import com.data.util.EventType;
import com.taurus.core.entity.ITObject;
import com.taurus.core.entity.TObject;
import com.taurus.core.plugin.redis.Redis;

public class GroupPublisherService {
	public static final String CHANNEL_NAME = "mgr_group";

	private static final String CMD_UPDATE_MEMBER = "update_member";

	private static final String CMD_DEL_ROOM = "del_room";

	private final static String EVT_TYPE = "E";
	private final static String EVT_UID = "uid";

	private final static String EVT_KEY = "event_";

	/**
	 * 1 hp 2 等级 3 合伙人等级
	 * 
	 * @param groupId
	 * @param uid
	 * @param type
	 * @param value
	 */
	public static void updateMemberEvt(int groupId, int uid, int type, int value) {
		ITObject data = TObject.newInstance();
		data.putInt("gid", groupId);
		data.putInt("uid", uid);
		data.putInt("type", type);
		data.putInt("value", value);
		data.putString("cmd", CMD_UPDATE_MEMBER);
		Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
	}

	public static void delRoomEvt(int groupId, String roomid) {
		ITObject data = TObject.newInstance();
		data.putInt("gid", groupId);
		data.putString("roomid", roomid);
		data.putString("cmd", CMD_DEL_ROOM);
		Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
	}

	/**
	 * 返还钻石
	 * 
	 * @param uid
	 * @param pay
	 * @param groupId
	 */
	public static void refundDiamo(int uid, int pay, int groupId, int gameId) {
		ITObject data = TObject.newInstance();
		data.putInt("pay", -pay);
		data.putInt("game", gameId);
		if (groupId > 0) {
			data.putInt("group", groupId);
		}
		//sendEvt(EventType.REDIS_EVENT_BACK_PAY, uid, data);
	}

	private static void sendEvt(int type, int uid, ITObject data) {
		int id = uid % 10;
		data.putInt(EVT_UID, uid);
		data.putInt(EVT_TYPE, type);
		Redis.use(EventReceiver.CHACHE_KEY).lpush(EVT_KEY + id, data.toJson());
	}
}
