I'm not sure how you would go about it Thailand, I have just arranged mine from the UK. Lots of services online and it's pretty cheap around £30, they send you a antigen test with code printed on it. You just take it with you and when you decide to return you do the test, take a photo of the result and they email you a result notification signed by a doctor. The websites explain in more detail but that's basically it...
You will be asked to show it at check in, airline may refuse boarding but legally they shouldn't. UK says you can board but you will get a fine think it's £500 same as the passenger locator form.