APFS partition inaccessible, container missing
I'm running macOS Mojave on a late-2015 4k 21.5" iMac.
I have lost access to my internal hard drive, but I can use my iMac by running macOS from an external drive or through recovery mode.
When I hold down the option key on boot, the only available drive shown is my external one. Last time I tried booting without holding option, I was greeted by the folder icon with the question mark in it.
I have not deleted my data, not even accidentally, it is all still there and I can see it using iBoysoft APFS data recovery.
This problem started when I tried to install Ubuntu on a partition (I tried to follow all the steps carefully, but I may have made a mistake) and afterwards in disk utility my drive was called FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF. My Mac was still running fine, but when I restarted it, it would no longer boot into macOS. I searched the internet for this problem and any solutions and I found a few. I went through these guides and did as they said, and I'm pretty confident I changed the numbers for sizes etc. correctly for my own situation, but even after following these guides I still cannot boot into macOS on my internal HD.
My HD is 1TB, my mac partition is 960GB, my Ubuntu one was 40GB but I deleted that and installed macOS Sierra on it, but that disappeared at some point too.
I managed to get my Mac to recognise that the data is in APFS format and that it's actually there, it just wont interact with it outside of terminal.
My APFS partition doesn't seem to have a container, as far as I understand APFS (not very far), it needs a container. I did not delete the container but I think it has been lost. Maybe it need to be rebuilt or the APFS partition needs to be put in one somehow, but I don't know how to do either of those things.
Another note is that the partition was 960GB but now shows as 883GB - I don't know what this means, that may have been the amount of data on the partition, but that seems maybe a little high.
I'm not nearly good enough with macOS or terminal to be messing around with it without help and I probably shouldn't have tried to install Ubuntu on my main hard drive without a recent backup, but I could really do with some help and I'd appreciate it a lot.
here are the results of some terminal commands, they will be more reliable than my guesses and explanations:
diskutil list
sudo gpt -r show disk0
sudo dd if=/dev/disk0 bs=512 count=1 skip=409640 | hexdump -Cv
Thank you for any help or suggestions
iMac (Retina 4K, 21.5-inch, Late 2015), macOS Mojave (10.14)