local addonName, _EchoRaidTools = ...;

local _ExposedInternal = _EchoRaidTools:NewModule("ExposedInternal")

function _ExposedInternal:ADDON_LOADED()
    if not EchoInternal then
        local LibReadOnly = LibStub:GetLibrary("LibReadOnly")
        _EchoRaidTools.fakeInternal = {}

        function tSClone(orig)
            local orig_type = type(orig);
            local copy;
            if orig_type == 'table' then
                copy = {};
                for orig_key, orig_value in pairs(orig) do
                    copy[orig_key] = orig_value;
                end
            else -- number, string, boolean, etc
                copy = orig;
            end
            return copy;
        end

        function tDClone(orig)
            local orig_type = type(orig);
            local copy;
            if orig_type == 'table' then
                copy = {};
                for orig_key, orig_value in next, orig, nil do
                    copy[tDClone(orig_key)] = tDClone(orig_value);
                end
                setmetatable(copy, tDClone(getmetatable(orig)));
            else -- number, string, boolean, etc
                copy = orig;
            end
            return copy;
        end

        ----------------------------------------------------------------------------------------------------------------------
        -- @Grim do we want to do this to reduce the amount of public WA releasing cleanup? This would have one 
        --       flaw: People without ERT could not use how public WA's, which is not optimal. But in the long run, we will 
        --       anyways end up in this scenario i.e. if a WA tries to read our parsed note from ERT.
        ----------------------------------------------------------------------------------------------------------------------
        local function logFn(...)
        end

        elog, eLog, Elog, ELog, ELOG = logFn, logFn, logFn, logFn, logFn
        elogl, eLogl, Elogl, ELogl, ELOGL = logFn, logFn, logFn, logFn, logFn

        function vdt(...)
            if ViragDevTool_AddData then
                ViragDevTool_AddData(...)
            end
        end

        VDT = vdt
        ----------------------------------------------------------------------------------------------------------------------

        function _EchoRaidTools.fakeInternal:UnitName(unit)
            local name, server = UnitName(unit);

            if (not name) then
                return nil;
            elseif (server and server ~= "") then
                name = name .."-".. server;
            end

            return name;
        end

        local function noop()
        end

        _EchoRaidTools.fakeInternal.RemoteLog = noop;

        elog, eLog, Elog, ELog, ELOG = noop, noop, noop, noop, noop
        elogl, eLogl, Elogl, ELogl, ELOGL = noop, noop, noop, noop, noop
        vdt, VDT = noop, noop

        _ExposedInternal:ExposeInspect()
        _ExposedInternal:ExposeGlow()
        _ExposedInternal:ExposeMarker()
        _ExposedInternal:ExposeNoteParsing()

        _G["EchoInternal"] = LibReadOnly:New(_EchoRaidTools.fakeInternal)
    end
end