minecraft:cannot_be_attacked for you with a switch.Get GodCraftOverview
minecraft:cannot_be_attacked is an entity component: it goes in the components object of a custom mob, or in one of its component groups. Stops other entities from attacking this one. Only entities with minecraft:ignore_cannot_be_attacked can still hit it.
Example
Inside the components object of BP/entities/<name>.json (values are the defaults or placeholders):
BP/entities/<name>.json
{
"minecraft:cannot_be_attacked": {}
}