-- =========================================================
-- Speed Camera BR — Owner Sync Event (Server -> Clients)
-- =========================================================
-- Sincroniza qual fazenda é dona dos radares.

SC_OwnerSyncEvent = {}
SC_OwnerSyncEvent_mt = Class(SC_OwnerSyncEvent, Event)

InitEventClass(SC_OwnerSyncEvent, "SC_OwnerSyncEvent")

function SC_OwnerSyncEvent.emptyNew()
    return Event.new(SC_OwnerSyncEvent_mt)
end

function SC_OwnerSyncEvent.new()
    return SC_OwnerSyncEvent.emptyNew()
end

function SC_OwnerSyncEvent:writeStream(streamId, connection)
    streamWriteInt8(streamId, SpeedCameraOwner.ownerFarmId or 0)
end

function SC_OwnerSyncEvent:readStream(streamId, connection)
    SpeedCameraOwner.ownerFarmId = streamReadInt8(streamId)
    self:run(connection)
end

function SC_OwnerSyncEvent:run(connection)
    print(string.format("[SpeedCameraBR] [CLIENT] Dono sincronizado: farmId=%d",
        SpeedCameraOwner.ownerFarmId or 0))
end

function SC_OwnerSyncEvent.broadcast()
    if not g_server then return end
    g_server:broadcastEvent(SC_OwnerSyncEvent.new())
end

function SC_OwnerSyncEvent.sendToClient(connection)
    if not g_server or connection == nil then return end
    connection:sendEvent(SC_OwnerSyncEvent.new())
end
