I have a basic understanding of DC circuits from high school and university physics courses, but those courses only covered circuits that discharge batteries.
I'm trying to build an rudimentary electrical system for the inside of a trailer. It'll be used for a few LEDs for lighting, USB ports for device charging, and an inverter for a few 110v outlets. The system will be powered from its own lead-acid battery (not charged by the car's alternator), that's chargeable via a solar panel on the roof, or by plugging it in.
I have no experience in this domain, and couldn't find the information on this (perhaps I just can't think of the right keywords to google). Fundamentally, what determines if a battery is being charged in a circuit, vs being discharged? For example, how can I ensure that if the system is plugged into a mains outlet, that the energy comes from the wall plug and not the battery?