-- laundering/cl_net.lua
-- Réception des messages réseau côté client.
-- Délègue l'affichage UI à cl_ui.lua via les fonctions Laundering.UI.*

Laundering    = Laundering    or {}
Laundering.UI = Laundering.UI or {}

-- ============================================================================
-- S→C : Laundering.OpenMenu
-- Payload : Entity npc + UInt dirty (30 bits)
-- ============================================================================

net.Receive("Laundering.OpenMenu", function()
    local npc   = net.ReadEntity()
    local dirty = net.ReadUInt(30)

    if Laundering.UI.OpenMenu then
        Laundering.UI.OpenMenu(npc, dirty)
    end
end)

-- ============================================================================
-- S→C : Laundering.Started
-- Payload : UInt amount (30) + Float duration + String methodId (64)
-- ============================================================================

net.Receive("Laundering.Started", function()
    local amount   = net.ReadUInt(30)
    local duration = net.ReadFloat()
    local methodId = net.ReadString()

    if Laundering.UI.OnStarted then
        Laundering.UI.OnStarted(amount, duration, methodId)
    end
end)

-- ============================================================================
-- S→C : Laundering.Completed
-- Payload : UInt dirtyIn (30) + UInt cleanOut (30) + Bool isPartial + String methodId
-- ============================================================================

net.Receive("Laundering.Completed", function()
    local dirtyIn  = net.ReadUInt(30)
    local cleanOut = net.ReadUInt(30)
    local isPartial = net.ReadBool()
    local methodId  = net.ReadString()

    if Laundering.UI.OnCompleted then
        Laundering.UI.OnCompleted(dirtyIn, cleanOut, isPartial, methodId)
    end
end)

-- ============================================================================
-- S→C : Laundering.Cancelled
-- Payload : UInt amount (30) + String reason (32) + String methodId (64)
-- ============================================================================

net.Receive("Laundering.Cancelled", function()
    local amount   = net.ReadUInt(30)
    local reason   = net.ReadString()
    local methodId = net.ReadString()

    if Laundering.UI.OnCancelled then
        Laundering.UI.OnCancelled(amount, reason, methodId)
    end
end)

-- ============================================================================
-- S→C : Laundering.Error
-- Payload : String msg (128)
-- ============================================================================

net.Receive("Laundering.Error", function()
    local msg = net.ReadString()

    if Laundering.UI.OnError then
        Laundering.UI.OnError(msg)
    end
end)
