Create Object that sometimes is nil

Hello.
How do I set the ‘cost’ (nested ) object to be ‘nil’ when my type is ‘Create
and to populate it with data when the type is any other