I had code violation issues in rentals I had. For me, I hired expeditors from the area, they're familiar with the local codes, recommend the correct way to mitigate, and in the end, turned out cheaper.
One of the violations is an illegal apartment, would've cost $35K or more to have it totally torn down, blueprints drawn, and rebuilt. My expeditor were friends with the assistant commissioner, had lunch, the order was reversed, we had the blueprints done, minor changes made, the total job cost $6K including the expeditor fees. The expeditor knew the logic behind the original order, i.e. tearing down the unit, convinced the assistant commissioner why it didn't apply to me, and fill out the paperwork for the permits in a way to mitigate fees. This saved numerous often stressful trips to code enforcement, saved time and money in the process. I wouldn't be able to do it by myself, don't even know where to start, what to ask for, when running down to the enforcement office.
Coincidentally when the job was completed and ready for inspection, turned out the entire code enforcement staff but one in the county was arrested for accepting bribes, so we had to hire private inspectors of our own to inspect and file the reports, which was approved. Thinking back, it was either paying bribes, getting arrested, or paying expeditor fees, rest easy, and let the expeditor handle everything.