As described by several Western visitors (such as the Córdoban nobleman Pero Tafur and the Florentine Cristoforo Buondelmonti), the church was in a dilapidated state, with several of its doors fallen from their hinges; Mehmed II ordered a renovation as well as the conversion. Mehmet attended the first Friday prayer in the mosque on 1 June 1453. Aya Sofya became the first imperial mosque of Istanbul. To the corresponding Waqf were endowed most of the existing houses in the city and the area of the future Topkapı Palace. From 1478, 2,360 shops, 1,300 houses, 4 caravanserais, 30 boza shops, and 23 shops of sheep heads and trotters gave their income to the foundation. Through the imperial charters of 1520 (AH 926) and 1547 (AH 954) shops and parts of the Grand Bazaar and other markets were added to the foundation.
who turned the hagia sophia into a mosque
Mehmed II