Without going through your script in detail, I’m confident that Picard can be made to do what you need. I suggest that you have a look at the Scripting section of the Picard User Guide, especially the Scripting Functions and Tags & Variables sections. There’s also a simple File Naming Script Tutorial that you might find useful.
There are many examples of file naming scripts out there, including the one that I use for my collection. You can also get a lot of good ideas and suggestions from the thread:
Finally, if you have any specific questions while developing your script, just ask and I’m sure someone will be able to help.