Rebecca, experiences like this are so exhausting and frustrating, but you are absolutely right - never give them the satisfaction of knowing they’ve got to you. If you show emotion then they’ve won and might use your reaction to escalate the situation.
At immigration I’m always polite and engaging it’s not worth the hassle to be any other way with them.
I’ll share my Swiss border control experience one day