Multifunctionalities of 2D MoS2 self-switching diode as memristor and photodetector