Find the largest prime number $p<1000$ for which there exists a complex number $z$ satisfying the following conditions:
- the real and imaginary parts of $z$ are both integers;
- $|z|=\sqrt{p}$; and
- there exists a triangle whose three side lengths are $p$, the real part of $z^3$, and the imaginary part of $z^3$.