When up against a Ditto, use the move Imprison.
Foe Ditto keeps using Struggle.
You can also use Substitute, to not take damage from Struggle/
This will always work, for Ditto's only move is Transform.
It's Hidden Ability is Impostor , which is almost same as Transform.
Happy Foe-Ditto-Annoying! :)