How can I safely buy a property in Spain?

Houses and flats on the Iberian Peninsula are of increasing interest to Poles. It is enough to mention that only between January and March 2024, our compatriots purchased 800 properties in Spain. So how can such a transaction be carried out safely?