from datetime import datetime


def save_system_to_file(system, filename="solar_state.txt"):
    with open(filename, "w", encoding="utf-8") as file:
        file.write(f"Saved: {datetime.now()}\n")
        file.write(f"Paused: {system.paused}\n")
        file.write(f"Show orbits: {system.show_orbits}\n\n")

        for star in system.stars:
            file.write(f"{star.name}: x={round(star.x, 2)}, y={round(star.y, 2)}, radius={star.radius}\n")
            for planet in star.planets:
                file.write(
                    f"  Planet orbit={planet.orbit_number}, "
                    f"x={round(planet.x, 2)}, y={round(planet.y, 2)}, "
                    f"radius={planet.radius}, speed={round(planet.speed, 4)}\n"
                )
            file.write("\n")
