Bidirectional USB Type C charging
The USB Type-C doesn't work as you described. The load of ideas how the port should opreate (as dual-role port) is described in the original USB Type-C specifications, which are freely available from USB.org, as part of entire USB 3.2 zipped package. 

Initially none of Type-C port will have any voltage on VBUS, so you can't use it as detector who is provider, and who is consumer. The role of a port is determined by pulls (up or down) on CC pins. And the CC wire goes from one port to linked port over C-C cable. Once the right combination is established and recognized, the source will put out VBUS, and the consumer will take it. For details please examine Section 4 of Type-C specifications, all variants of connectivity are pictured there.