Spin coupling of two identical complex ions. I. Theory