Changing smart plugs / migrating zigbee, long term stats question

I have to change out a few smart plugs and Im also considering moving from ZHA to Z2M. However, I dont want to lose all my long term stats. Im confused how to best proceed. A few questions

Are long term device consumption stats tied only to the entity_id ? Ive seen automations use not only an entity_id but also a device_id:, something like 3501f14ba984b218cff6399417ecf5a5, is that used too?
What happens when you rename the entity_id of the energy consumption sensor, do you lose all the old data, do you get data for the old and new entity_id separately as if its a different device, or does it just get renamed?

Say I have a device called plug A, with an energy consumption entity called sensor.pluga_summation_delivered. If I delete this device, do I lose the statistics? If not, what happens when I pair a new plug and give it the same entity_id ?

Any pointers would be appreciated.