1. Depends on the encounter, and the game the encounter is from. If it is sufficiently random, it doesn't have a type.
2. Tera raids have a detectable correlation.
3. No, because there is no algorithm to enable realtime checks. If people switch boxes in the UI, the program shouldn't freeze for 3 minutes for each Pokemon needing the check.
4. To write checking algorithms, you have to understand how they're generated and then just test the result against the starting conditions. A seed generates values in sequence. PKHeX has numerous of these, and the source code is hosted on GitHub for anyone to read.