Is it possible to code a DPDT switch?

Replace the switch with a DPDT relay controlled by the Arduino. If you want to then 'hit the switch' by hand, wire a SPST on-off-on switch to two arduino inputs. On (left) would be auto, Off is manual off, On (right) is manual on. This is also known and an "HOA" (hand-off-auto) configuration.