If I am understanding design correctly yep you can have for equip button click just very simply run unequip and then maybe a wait of 0.1 seconds and then run equip.
Within unequip it looks like already if you have a weapon it will unequip it or skip if there is none which is fine.
For equip this is also fine except you need to move the logic from the else about the inventory slot into the equip function to release that slot.
Just a note you will probably encounter a future bug where if you try to equip a weapon and your inventory is full it will not unequip the weapon (expected) but it will still equip the item and move it to the slot so you have 2 in there. This is because the logic is really not a swap for swap logic but rather you are moving the weapon out to any slot then moving the item in. For a true swap you would need to edit the logic later maybe use the id of the inventory slot for item and move the weapon to it, then move the item to the weapon slot. As you know currently the weapon moves to the slot with lowest id and not the specific one the equipping item is in.