package com.group.service;

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_ADD_ROOM = "add_room";
    private static final String CMD_DEL_ROOM = "del_room";
    private static final String CMD_DEL_PLAY = "del_play";
    private static final String CMD_ADD_PLAY = "add_play";
    private static final String CMD_UPDATE_PLAY = "update_play";
    private static final String CMD_DEL_GROUP = "del_group";
    private static final String CMD_UPDATE_GROUP = "update_group";

    private static final String CMD_UPDATE_JOINS = "update_joins";
    private static final String CMD_UPDATE_MAIL_TIP = "update_mail_tip";
//    private static final String CMD_UPDATE_MEMBER = "update_member";

    public static void addRoomEvt(int groupId, String roomid) {
        ITObject data = TObject.newInstance();
        data.putInt("gid", groupId);
        data.putString("roomid", roomid);
        data.putString("cmd", CMD_ADD_ROOM);
        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());
    }

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

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

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

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

    public static void updateGroupEvt(int groupId, String name, boolean ban,String notice,int option,int showNum) {
        ITObject data = TObject.newInstance();
        data.putInt("gid", groupId);
        data.putString("cmd", CMD_UPDATE_GROUP);
        data.putString("name", name);
        data.putBoolean("ban", ban);
        data.putString("notice", notice);
        data.putInt("option", option);
        data.putInt("show_num", showNum);
        Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
    }

    public static void updateJoinsEvt(int groupId, int joins) {
        ITObject data = TObject.newInstance();
        data.putInt("gid", groupId);
        data.putInt("joins", joins);
        data.putString("cmd", CMD_UPDATE_JOINS);
        Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
    }
    
    public static void updateMailTipEvt(int groupId, int uid) {
        ITObject data = TObject.newInstance();
        data.putInt("gid", groupId);
        data.putInt("uid", uid);
        data.putString("cmd", CMD_UPDATE_MAIL_TIP);
        Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson());
    }

    /**
     * 1 hp 2 等级 3 合伙人等级
     * 
     * @param groupId
     * @param uid
     * @param type
     * @param value
     */
    public static void updateMemberEvt(int groupId, int uid, int type, int value) {
//        if (type == 1) {
//            return;
//        }
//        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());
    }
}
