local StateView = {}

local function copyCell(cell)
	local out = {}
	for key, value in pairs(cell) do
		out[key] = value
	end
	return out
end

function StateView.ToClientState(state)
	local gridCells = {}
	for key, cell in pairs(state.grid.cells) do
		gridCells[key] = copyCell(cell)
	end

	local offers = {}
	for _, offer in ipairs(state.conveyorOffers) do
		table.insert(offers, { eggType = offer.eggType, price = offer.price })
	end

	return {
		coins = state.coins,
		conveyorLevel = state.conveyorLevel,
		plotLevel = state.plotLevel,
		grid = {
			width = state.grid.width,
			height = state.grid.height,
			cells = gridCells,
		},
		pendingEggTokens = #state.pendingEggTokens,
		conveyorOffers = offers,
		lastOfferRefreshAt = state.lastOfferRefreshAt,
	}
end

return StateView
