General Theory of Josephson Diodes