local SEventDispatchCenter = {}

SEventDispatchCenter.EventType = {
    -- NET EVENT
    NET_CONNECT_STATE               = "NET_CONNECT_STATE",
    NET_LOGIN_RET                   = "NET_LOGIN_RET",
    NET_UPDATE_BASE_DATA            = "NET_UPDATE_BASE_DATA",
    NET_MODIFY_PLAYER_NAME_RET      = "NET_MODIFY_PLAYER_NAME_RET",
    NET_UPDATE_DATA_FINISH          = "NET_UPDATE_DATA_FINISH",
    NET_UPDATE_SERVER_TIME          = "NET_UPDATE_SERVER_TIME",
    NET_UPDATE_PLAYER_COIN          = "NET_UPDATE_PLAYER_COIN",

    -- TALENT
    NET_UPDATE_TALENT               = "NET_UPDATE_TALENT",

    -- SKILL
    NET_INIT_SKILL_LIST             = "NET_INIT_SKILL_LIST",
    NET_UPDATE_SKILL_LIST           = "NET_UPDATE_SKILL_LIST",
    NET_UPDATE_SKILL_INFO           = "NET_UPDATE_SKILL_INFO",
    NET_INIT_TRAIN_SKILL_LIST       = "NET_INIT_TRAIN_SKILL_LIST",
    NET_REMOVE_TRAIN_SKILL_LIST     = "NET_REMOVE_TRAIN_SKILL_LIST",
    NET_REMOVE_TRAIN_SKILL_INFO     = "NET_REMOVE_TRAIN_SKILL_INFO",
    NET_UPDATE_TRAIN_SKILL_LIST     = "NET_UPDATE_TRAIN_SKILL_LIST",
    NET_UPDATE_TRAIN_SKILL_INFO     = "NET_UPDATE_TRAIN_SKILL_INFO",
    NET_ADD_TRAIN_SKILL_INFO        = "NET_ADD_TRAIN_SKILL_INFO",

    -- ITEM
    NET_UPDATE_ITEM_LIST            = "NET_UPDATE_ITEM_LIST",
    NET_UPDATE_ITEM_INFO            = "NET_UPDATE_ITEM_INFO",
    
    -- UI EVENT
    UI_UPDATE_SYNC_STEP             = "UI_UPDATE_SYNC_STEP",
    UI_BATTLE_MATCH                 = "UI_BATTLE_MATCH",
    UI_UPDATE_SKILL_LIST            = "UI_UPDATE_SKILL_LIST",
    UI_UPDATE_SKILL_TRAIN_LIST      = "UI_UPDATE_SKILL_TRAIN_LIST",
    UI_DELETE_TRAIN_SKILL_LIST      = "UI_DELETE_TRAIN_SKILL_LIST",
    UI_DELETE_TRAIN_SKILL           = "UI_DELETE_TRAIN_SKILL",
    UI_CLOSE_SKILL_DETAIL_DIALOG    = "UI_CLOSE_SKILL_DETAIL_DIALOG",
    UI_UPDATE_TRAIN_SKILL_TIME      = "UI_UPDATE_TRAIN_SKILL_TIME",
    UI_CLOSE_MODIFY_PLAYER_NAME     = "UI_CLOSE_MODIFY_PLAYER_NAME",

    -- BATTLE EVENT
    BATTLE_MATCH_SUCCESS            = "BATTLE_MATCH_SUCCESS",
    DRAG_SKILL_MOUSE_POSITION       = "DRAG_SKILL_MOUSE_POSITION",
    START_MOVE                      = "START_MOVE",
    START_MOVE_RET                  = "START_MOVE_RET",
    SKILL_INDICATOR                 = "SKILL_INDICATOR",
}

SEventDispatchCenter.EventQuene = {}

function SEventDispatchCenter:RegisterEvent(eventType, callback)
    print("--------------------> KEventDispatchCenter:RegisterEvent eventType", eventType, callback)
    if self.EventType[eventType] == nil or type(callback) ~= "function" then
        print("KEventDispatchCenter:RegisterEvent param is error~ eventType:", eventType)
        return
    end
    
    if self.EventQuene[eventType] == nil then
        self.EventQuene[eventType] = {}
    end
    
    --local index = table.getn(self.EventQuene[eventType])
    --self.EventQuene[eventType][index + 1] = callback
    table.insert(self.EventQuene[eventType], callback)
end

function SEventDispatchCenter:UnregisterEvent(eventType, callback)
    print("--------------------> KEventDispatchCenter:UnregisterEvent eventType", eventType, callback)
    if self.EventQuene[eventType] == nil or type(callback) ~= "function" then
        print("KEventDispatchCenter:UnregisterEvent param is error~ eventType:", eventType)
        return
    end
    
    for k, v in pairs(self.EventQuene[eventType]) do
        if callback == v then
            table.remove(self.EventQuene[eventType], k)
            return
        end
    end
end

function SEventDispatchCenter:DispatchEvent(eventType, ...)
    print("--------------------> KEventDispatchCenter:Dispatch eventType", eventType)
    if self.EventType[eventType] == nil then
        print("KEventDispatchCenter:DispatchEvent eventType is unknow : ", eventType)
        return    
    end

    if self.EventQuene[eventType] == nil then
        print("KEventDispatchCenter:DispatchEvent callback is nil eventType:", eventType)
        return 
    end
    
    for k, v in pairs(self.EventQuene[eventType]) do
        v(...)
    end
end

return SEventDispatchCenter