AC is a heatpump. pumping heat from inside to outside. “Heatpump” is also a heatpump. pumping from outside in. The only difference is fluid flow direction.
Hence only thing needed to turn one to other is 4 way valve changing the flow direction/order of refrigerant.
These days atleast in Europe, good luck finding “heat pump”, that doesn’t have 4 way selector valve. Early on there was single direction heat pumps and cooling was extra feature only on upmarket models. These days it is “oh right it also has cooling, handy”. The valve is not that expensive, so it is pretty standard by now.
4 way valve is 4 way exactly so the compressor can essentially switch sides on the cycle. It also shifts around where the expansion valve is located in cycle. thus switching the tasks of the inside and outside radiators/heatexchangers.