When fighting a fire, you use what you have at hand.
Foam is mostly for LIQUID chemicals/fuels. The lithium in batteries is a solid metal.
If the fire is isolated to the engine compartment, water should be all you need. If you only have a fire extinguisher, use that.
If the fire department gets to the site quickly enough, they may use foam depending on how involved the vehicle is and whether the vehicle is leaking fuel and other liquids. If fuel, oil, hydraulic fluid, etc. are already contributing to the fire, then foam is probably needed.
One of the biggest concerns in a vehicle fire is explosion. Not only from the fuel, but from the many struts found on cars. They are installed on bumpers, hoods, trunks and elsewhere. Bumpers have been known to explode from the vehicle and travel 75 feet or more.
Tires can also explode, sheering off hubs, wheels and axles and sending them flying.
Beware of combustible metals on vehicles, such as magnesium,
lithium, titanium and others used in engine blocks, steering wheels, rims and other parts. When ignited, these materials give off white smoke and a distinct white flame that can intensify when hit with water.
Tires can be huge problems when filled with something other than regular air.
If you're putting out a car fire before the fire department arrives, stay as far back as possible using the full reach of the water or extinguisher on the flames. When it's out, stay back to let it cool before approaching, as struts and tires can still be hot enough to explode.
Nothing's ever as simple as we imagine.
https://www.firefighternation.com/firerescue/fighting-vehicle-fires/