how to move items from one slot to another

so ive been trying to work on a system that makes it so the first 3 slots in the hotbar can ONLY carry "weapons", and the rest store "items" (currently testing with a diamond sword and an apple)

so far ive: made it detect weapons (diamond swords) in the first 3 slots made it so that the 1st slot (slot 0) can carry a diamond sword, but not anything else by deleting the item

i want it to instead of just deleting the item it moves it to a different slot, and ive already kinda had a logic train in my head on how it would do that (although possibly pretty inefficent) by making a function for every slot, basically i want it to check what the item is and see if it is tagged as "item", if not it moves into the main inventory (i have another system in mind but thats not in this current itteration as im just getting the systems working), and if it is it checks to see if the 4th slot in the hotbar is free, if not it moves to the next one and does the same procedure, if so it makes a copy of the item that was in the 1st - 3rd slot and moves it to the first availble slot from 4-9. is this possible?

(sorry if this is a bit incoherent, im having a hard time figuring out how to phrase what i needed haha)

Continue to help post