Controlling direction of current flow through pin depending on the type of device connected
You are making this too difficult. All you need to do is a battery switch that will disconnect BAT line when no accessories are plugged in. This is trivial to do with a single MOSFET (it will have a protection diode, so make sure you connect it such that you cannot discharge the battery when MOSFET is off). A microcontroller should open the MOSFET when device is plugged in, and then it will be virtually indistinguishable from the wire.

Your only concern left is what happens when battery runs down. Well, in this case the MOSFET's protection diode will help -- it will allow some limiting battery charging even when MOSFET is off. It will not allow full charging due to voltage drop, but it does not matter -- the moment the battery has just a bit of power, MCU will start up and open the MOSFET.