At the end of each turn, you can either get damaged, or get healed, but what goes first when both appear. For example, you can get damaged from the hail, but your Pokemon is holding a leftovers, what would go first? There are many more different examples, take damaging from status(burn/poison) and healing due to a used move, could be leech seed. Is there in both examples a standard rule for what goes first?
Such things could make the difference between your Pokemon fainting or surviving, if your Pokemon is at like 3 hp and a sandstorm is up, it would most likely die, but if its leftovers or something would do its effect first, he would survive the hit.
So, is this completely random or is there some rule or (negative) priority on these things that happen at the end of turn?