You'll likely need to store which attachments the gun has using NBT or capabilities.
There are several possible ways to handle the model:
Create a model for each possible state of the gun (e.g. no attachments, scope, bi-pod, scope and bi-pod, etc.) and register an ItemMeshDefinition to choose the appropriate one based on the current attachments.
Create the base gun model and a model for each attachment and combine them as submodels using Forge's blockstates format. You'll still need to register an ItemMeshDefinition to choose the appropriate variant of the blockstates file based on the current attachments.
Generate the models at runtime with an ICustomModelLoader, IModel and IBakedModel. Forge has several examples of this.