ZConference = ZConference or {}

ZConference._data = nil

function ZConference.SetStart(bStart)
    ZConference._data.bStart = bStart
end

function ZConference.GetStart()
    return ZConference._data.bStart
end

function ZConference.UpdateMeetingScreenInfo(res)
    local tData = res.data

    if not tData then
        print("----> MeetingInfo data not exit!")
        return
    end

    local tScreenMainInfo = {}
    local tScreenSideInfo = {}

    for _, tScreenInfo in pairs(tData) do
        local szScreenId = tostring(tScreenInfo.screenId)
        if tScreenInfo.screenType == SCREEN_TYPE.MAIN then
            -- table.insert(tScreenMainInfo, tScreenInfo)
            tScreenMainInfo[szScreenId] = tScreenInfo
        end

        if tScreenInfo.screenType == SCREEN_TYPE.SIDE then
            -- table.insert(tScreenSideInfo, tScreenInfo)
            tScreenSideInfo[szScreenId] = tScreenInfo
        end
    end

    ZConference._data.tScreenMainInfo = tScreenMainInfo
    ZConference._data.tScreenSideInfo = tScreenSideInfo


    local eventManager = ZConference._eventManager
    eventManager:DispatchEvent(eventManager.EventType.UPDATE_MEETING_SCREEN)
    PrintTable(tScreenMainInfo, "----> tScreenMainInfo")
    PrintTable(tScreenSideInfo, "----> tScreenSideInfo")
end

function ZConference.GetScreenMainInfo()
    return ZConference._data.tScreenMainInfo
end

function ZConference.GetScreenSideInfo()
    return ZConference._data.tScreenSideInfo
end

function ZConference.SetMeetingId(res)
    print("----> res.data.meetingId",  res.data.meetingId)
    ZConference._data.meetingId = res.data.meetingId
end

function ZConference.GetMeetingId()
    return ZConference._data.meetingId
end

local function RegisterEvent()
    local eventManager = require("Base/ZEventDispatchCenter.lua")
    eventManager:RegisterEvent(eventManager.EventType.CONFERENCE_START, ZConference.SetStart)
    eventManager:RegisterEvent(eventManager.EventType.JOIN_MEETING_REQ, ZConference.SetMeetingId)
    eventManager:RegisterEvent(eventManager.EventType.MEETING_SCREEN_RESP, ZConference.UpdateMeetingScreenInfo)
end

local function UnregisterEvent()
    local eventManager = require("Base/ZEventDispatchCenter.lua")
    eventManager:UnregisterEvent(eventManager.EventType.MEETING_SCREEN_RESP, ZConference.UpdateMeetingScreenInfo)
    eventManager:UnregisterEvent(eventManager.EventType.JOIN_MEETING_REQ, ZConference.SetMeetingId)
    eventManager:UnregisterEvent(eventManager.EventType.CONFERENCE_START, ZConference.SetStart)
end

function ZConference:Init()
    print("ZConference.Init")
    self._data = {}
    self._eventManager = require("Base/ZEventDispatchCenter.lua")

    RegisterEvent()
end

function ZConference:UnInit()
    print("ZConference.UnInit")
    UnregisterEvent()

    ZConference._data = nil
end