Hi, I'm back with another question to make everyone's life a bit harder (at least for me

).
Would it be possible to change the Tera Type of a wild Pokémon (a boss Pokémon) using a script?
I'm planning a three-phase battle in which, during the last two phases, the Pokémon would use different Tera Types. Here are the factors to consider:
Phase One: The Pokémon shouldn't use Terastallization. I assume this is easy to handle by simply not including the battle rule that enables Terastallization.
Phase Two: After restoring its HP to 100%, the Pokémon activates Terastallization via a forced script. So far, so good.
Phase Three: Upon being "defeated" again (i.e., when Terastallization ends after reaching 20% HP), it would restore its HP to 100% once more and activate
a second Terastallization with a different Tera Type. And this is where things get tricky.
So my question is:
Is it possible to change a Pokémon's Tera Type mid-battle using a script?