First-Principles Calculation of Optoelectronic Properties in 2D Materials: The Polytypic WS2 Case