water datapack

Im trying to make a datapack that makes it so if a player is out of the water there's a timer that if it runs out the player will take damage and the timer will reset only if the player covers its head with water kinda like a reverse water breathing. But i can't fogure out how to do it. P.S. : i already know how to detect if water is on top of a player.
Continue to help post