How to prove Gaussian Integers is a UFD Formally Without using the idea of "Every ED is a UFD" i am trying to prove $$Z[i]=\left\{a+bi:a,b \in Z\right\}$$ is a UFD
My try:
case $1.$ Let $GCD(a,b) =d\ne 1$  then  $$(a+bi)=d \times (m+ni)$$ where $GCD(m,n)=1$
Case $2.$ If $GCD(a,b)=1$
Let $$(a+ib)=(p+iq)(r+is)$$
So we get:
$$(a^2+b^2)=(p^2+q^2)(r^2+s^2)$$
If $a^2+b^2$ is Prime Then the Unique Factorization of $a+ib$ is Itself.
If $a^2+b^2$ is Composite say $N_1N_2$
Then $p^2+q^2=N_1$ and $r^2+s^2=N_2$ then how can we guarantee that there exists integers $p,q,r,s$ satisfying these two equations?
Here are some examples i tried:
Ex $1.$ $2+3i$=$2+3i$
Ex $2.$ $8+4i=2 \times 2 \times (2+i)$
Ex $3.$ $7+4i=(2+3i)(2-i)$
EDIT:
With some observation i came up with a fact which i am not sure whether it is universally true.
"If $GCD(a,b)=1$ and $a^2+b^2$ is Composite then $a^2+b^2$ can be decomposed in to product of exactly two Primes"
If this is TRUE, then i am done with my Original Proof.
 A: It is well known that every $\mathrm{PID}$ is $\mathrm{UFD}$. It's enough to prove that $\mathbb{Z}[i]$ is a $\mathrm{PID}$. Here is a formal proof which shows that $\mathbb{Z}[i]$ is an $\mathrm{ED}$ and hence a $\mathrm{PID}$.
$\mathbb{Z}[i]$ is a Euclidean Domain:

We will show that for any two Gaussian integers $\alpha,\beta$, $\exists$ $\mu$ and $\rho$ in $\mathbb{Z}[i]$ such that $\alpha=\mu\beta+\rho$ and $N(\beta)>N(\rho)$. Consider the principal ideal $(\beta)$ generated by $\beta$. In the complex plane, let $O$ be the origin and the point $A$ represents the number $\beta$. Multiplication by $i$ rotates the vector $OA$ through $90^{\circ}$. Let $B$ be the point in the complex plane representing $i\beta$. Then $\angle AOB=\frac{\pi}{2}$. Now the elements of $(\beta)$ are sums or differences of the numbers $\beta$ and $i\beta$. Hence it forms a square grid with each square of side length $|\beta|$ which is same as $\sqrt{N(\beta)}$. Every element of $\mathbb{Z}[i]$ lies in the interior or on the boundary of such a square. Hence $\exists$ a nearest corner point of some square from $\alpha$. There maybe more that one such nearest corner point but we pick one such, $\mu\beta$(say) for some $\mu\in\mathbb{Z}[i]$. Then the distance from the corner to the point $\alpha$ must be strictly less than the side length of these squares. Hence $|\alpha-\mu\beta|<|\beta|$. Take $\rho=\alpha-\mu\beta$. Then clearly from the above observation $N(\beta)>N(\rho)$.

$\mathbb{Z}[i]$ is a $\mathrm{PID}$:

Let $\mathfrak{a}$ be a non-zero ideal of $\mathbb{Z}[i]$. Consider the set $\mathcal{N}=\{N(\alpha):\alpha\in\mathfrak{a}\setminus\{0\}\}$. Being a set of positive integers, $\mathcal{N}$ must have a minimum element
(Well-ordering principle). Let $\alpha_0\in\mathfrak{a}$ be such that $N(\alpha_0)$ is minimum. Let $\alpha\in\mathfrak{a}$. Then by the previous part $\exists$ $\beta$ and $\rho$ in $\mathbb{Z}[i]$ such that $\alpha=\beta\alpha_0+\rho$ and $N(\alpha)>N(\rho)$. Since $\mathfrak{a}$ is an ideal, $\alpha-\beta\alpha_0=\rho\in\mathfrak{a}$. But if $\rho\neq0$, it contradicts the minimality of $N(\alpha_0)$. Hence $\rho$ must be $0$. Hence $\alpha=\beta\alpha_0\in(\alpha_0)$. Hence $\mathfrak{a}\subset(\alpha_0)$. Again since $\alpha_0\in\mathfrak{a}$, trivially $(\alpha_0)\subset\mathfrak{a}$. Hence $\mathfrak{a}$ is the principal ideal generated by $\alpha_0$.

