Adding multiple types of terrain and also making it possible to paint the edges of course will add an explosion of possible tile types that are required. Looks like there is support in Tiled for optional automatic mirroring or rotations to add missing tile variations.
Tiled uses tile "Global IDs" that encode booleans for flip and rotation into the upper bits: https://doc.mapeditor.org/en/latest/reference/global-tile-id...
It's kind of a pain in the ass to implement IMHO because you need to strip these bits and iterate all of your tilesets to find the correct tileset and tile for the GID for every ID (which is what the tile layers actually store) but a lot of the inherent performance issues can be improved upon by caching the last result, since consecutive tiles in a tilemap are likely to repeat.
Also I found this page useful: https://eishiya.com/articles/tiled/
Seems to be getting the hug of death.
In the beginning, you're looking up a set of UVs in a table indexed by some mask value.
In the end, you're debugging errors where one off by one error cascades into strange realms of indexing the wrong (unloaded) chunk with coordinates rolling over to positions that make no sense, looking up neighbours that look one way yet you end up drawing something completely different.
The suggest solution is an elegant and relatively common approach to what would otherwise be a naive series of nested 40+ if statements consisting of much swearing and sprite editing.