Rotate 180 degrees over x axis over time

I have an object(shark) moving up and down and when it’s at the bottom, it rotates 180 degrees. But sometimes it turns over it’s belly and sometimes over it’s back. I want to have it so that it always rotates on it’s belly and not on it’s back. How can I fix this?

Also the starting rotation is -90 degrees X axis. Here’s the code:

void FixedUpdate()
{
    transform.Translate(Vector3.forward * speed * Time.deltaTime);
    targetAnglesUp = transform.eulerAngles + 180 * Vector3.right; // what the new angles should be
    targetAnglesDown = transform.eulerAngles + 180 * Vector3.right; // what the new angles should be
    if (transform.position.y >= 150)
    {
        
        transform.eulerAngles = Vector3.Lerp(transform.eulerAngles, targetAnglesUp, smooth * Time.deltaTime); // lerp to new angles
    }

    if (transform.position.y <= 50)
    {
        
        transform.eulerAngles = Vector3.Lerp(transform.eulerAngles, targetAnglesDown, smooth * Time.deltaTime); // lerp to new angles
    }
}

You can add a Riggidbody (2D or 3D) and then scroll down to Constraints, and freeze its rotation so that it can only rotate on certain axis’.