Let $b \in \mathbb R^n $ and $A \in \mathbb R^{m\times n}$ with $m \geqslant n$ and $\operatorname{rank}(A)\le n$. Prove that the following statements are equivalent;
$\hat{x} = \operatorname{argmin}_{x \in \mathbb R^n} \|Ax-b\|^2$
$A^t(b-A \hat{x})=0$.
I know that; $$ \|Ax-b\|^2 = (Ax-b)^t(Ax-b) = x^tA^tAx-2x^tA^tb+b^2. $$ Which can simplify to; $$ A^t(Ax-b) =0 $$
However I am still really confused if this is right and provides a full detailed proof of the equivalent please!
Hint: One approach is to calculate the derivative of $\| A x - b \|^2$, set it to zero and solve for $\hat{x}$.