Unfortunately, standardization is extremely poor. Because only mid-drives can provide good controllability (since practically no hub drive has a torque sensor), you want to choose mid-drive if you actually expect to be able to enjoy riding the e-bike.
Batteries can be re-celled, but sometimes the manufacturer makes it extremely hard. For example, generally the batteries can't be opened with standard tools. Also some manufacturers like Bosch make the entire battery depend on the continuous availability of voltage. If the voltage is lost, the battery is bricked. This means re-celling needs a continuous power supply, and if that is accidentally disconnected during the re-celling operation, the battery is bricked. Finding someone with experience to re-cell e-bike batteries may be tricky, and you can expect to pay a lot given how hard it has been made. Thus, for e-bikes where replacement batteries are available you probably want to buy a replacement battery. But once those will no longer be available, you want to re-cell. If you have an aging battery and you know you may need to purchase a replacement in the future, consider the likelihood of manufacturer discontinuing support, the easiness and cost of finding an experienced re-celler, and the cost of a replacement battery: it may be best to buy a replacement while you can.
Battery longevity is reduced by continuously charging it to full immediately after every ride. I have a 3-year old Bosch e-bike which I have charged to full after every single ride. Its 13.4 Ah 36 V battery took 126-127 minutes to charge from completely empty (or actually 3% full since there is a slight reserve for running the lights for two hours) to 80% full with a 4 ampere charger. If we can trust the charger to be actually 4 amperes, this might indicate that 8.43 amp-hours went in whereas with a new battery 10.32 amp-hours would have went in. Thus, the battery has about 82% of its capacity left (unfortunately I didn't do the very same test when the battery was new so take the 82% figure with a grain of salt). Of course this is a completely unscientific measurement since a nominally 4 ampere charger may actually be just tiny bit faster. For example my electric scooter has dual 2 A chargers that to me seem more like 2.1 A chargers based on state-of-charge increase rate because the battery charges bit faster than expected.
Unfortunately, e-bike manufacturers make it very hard to charge to 80% full every time. This would increase battery longevity manyfold. You can do it yourself by a timed charge. Generally reasonable rate charges charge at full rate to about 80% full and after that the charge rate begins to decrease, so calculations are easy.
If the e-bike has a percentage battery state of charge indicator with 1% accuracy (like my e-scooter has), do this:
- I rode my e-scooter to nearby grocery store and had 75% charge left, thus I want 5% more charge
- The battery is 15 amp-hour, thus I want 15 Ah * 0.05 = 0.75 Ah more charge
- The dual charges are nominally 4 A together but I suspect them to give approximately 4.2 A, so I want 0.75/4.2 * 60 = 10.7 minutes more charge, let's say 10 minutes for simplicity
- I attach the charger(s) to a mechanical timer and set it to 10 minutes. The timer will cut electricity automatically after 10 minutes. My timer cost 8 euros; I bought several of them.
If your e-bike only has 0/5, 1/5, 2/5, 3/5, 4/5, 5/5 bar indicator, you should operate it in this manner for most rides:
- Flat battery (0/5): you know you need 80% charge so calculate timer based on that state of charge
- Anywhere between 0-20% (1/5): assume 20% and you therefore need 60%
- Anywhere between 20-40% (2/5): assume 40% and you therefore need 40%
- Anywhere between 40-60% (3/5): assume 60% and you therefore need 20%
- Anywhere between 60-80% (4/5): it may already be at 80% so don't charge
- Anywhere between 80-100% (5/5): definitely don't charge
If you expect to do one occasional long ride, charge it to full immediately before that ride. The shorter the time a lithium ion battery spends at full charge, the better the longevity. Do this only for long rides because the fewer times you charge to full, the better the longevity.
Note this charging plan may leave the battery to 60% state of charge at worst since you may not see the battery state of charge to a high accuracy, some displays only have 0/5, 1/5, 2/5, 3/5, 4/5, 5/5 (5 bars). If this is a problem, consider buying an e-bike with 1% accuracy state of charge meter, or an e-bike with big enough battery.
Enough for the battery. Then what else could break? Lights generally are standardized, lots of compatible ones are available for sale. Cranks may use a rare form of attachment, but you may find compatible cranks for sale. If the attachment is rare, I'd recommend buying several cranks as spare parts while you can buy them. Some e-bikes with dual chainrings may have a rare spider, if you find a compatible spider for sale definitely buy one as spare.
Bottom bracket bearings are integral to the drive unit. Sometimes they may be replaceable by taking apart the drive unit, but that may not be easy. You may be at the mercy of the manufacturer.
Displays are non-standard, expect to not be able to buy a compatible display 20-30 years from now. Mid-drive units have a non-standard attachment to frame, if a drive unit breaks generally you have to expect to replace the entire bike, except if the drive unit breaks between 0-5 years, you may find a compatible one for sale. Rear wheel speed sensor is non-standard so you may want to buy one as spare as long as they are available for sale. Rear wheel magnets may be more powerful than cyclocomputer magnets but cheap to buy so buy as many magnets as you plan to have rear wheels plus maybe 2 extra in case you lose some of the magnets.
Generally, a mid-drive e-bike isn't a tool you can expect to last 20-30 years. I ride an e-bike because it saves me at least 50 hours per year and I expect it to last maybe 10 years with one replacement battery bought in that time. This makes the cost of the bike 4700 euros (cost of bike + 1 extra battery) during those 10 years, but the bike saves 500 hours during those 10 years. A normal comparable bike would have cost maybe 2000 euros and be usable for 30 years so that's about 670 euros during 10 years and the rest during the rest of the 30-year period. So about 4000 euros spent, about 500 hours saved, I'd say a pretty good deal for someone who earns higher-than-average salary.
If your goal is absolutely minimal costs and absolutely maximal serviceability, you may want to look at hub-drive bikes sourced from the communists. They not only cost less but may actually be even more serviceable. Unfortunately, you don't enjoy them as much since those hub-drive units generally lack torque sensor and this absolutely kills the enjoyment. If the goal is to enjoy, pick a good mid-drive unit. If the goal is to go from place A to place B at very minimal cost, then those hub-drive communist bikes may be better, but then again for cost-minimizing choosing a non-electric bike would be even better.