local map = ...

function map:on_opening_transition_finished()

  -- cut() on a cuttable destructible triggers on_cut and destroys it.
  local cut_called = false
  function bush_cuttable:on_cut()
    cut_called = true
  end

  bush_cuttable:cut()

  -- After cut(), the entity starts its destroy animation (is_being_cut = true)
  -- so get_modified_ground() returns "empty".
  assert_equal(bush_cuttable:get_modified_ground(), "empty")
  assert(cut_called, "on_cut() was not called")

  -- cut() on a non-cuttable destructible does nothing.
  bush_not_cuttable:cut()
  assert_equal(bush_not_cuttable:get_modified_ground(), "wall")

  -- cut() on a cuttable+regenerating destructible works; it also starts the
  -- destroy animation (ground becomes empty).
  bush_regenerating:cut()
  assert_equal(bush_regenerating:get_modified_ground(), "empty")

  -- After the destroy animation finishes, the non-regenerating bush is gone.
  sol.timer.start(map, 2000, function()
    assert(bush_cuttable == nil, "cuttable bush should be removed after cut animation")
    assert(bush_not_cuttable ~= nil, "non-cuttable bush should still exist")

    -- Calling cut() again while bush_regenerating is waiting to regenerate
    -- should be a no-op (guarded by is_waiting_for_regeneration()).
    local second_cut_called = false
    function bush_regenerating:on_cut()
      second_cut_called = true
    end
    bush_regenerating:cut()
    assert(not second_cut_called, "on_cut() must not fire while waiting to regenerate")

    sol.main.exit()
  end)
end
