Self-consistent Modeling of Gamma-ray Spectra from Solar Flares with the Monte Carlo Simulation Package FLUKA