Season the chicken thighs with salt and freshly ground pepper and set aside.
Heat the oil or clarified butter in a heavy skillet over medium heat. Add the diced onion and cook, stirring occasionally, until soft and translucent, about 5 minutes.
Remove the cooked onions to a plate. Add the chicken to the pan, skin side down, and brown on one side, then turn and brown the other side, about 10 to 15 minutes total.
Return the onions to the pan. Add the minced garlic, minced ginger, and ground turmeric and cook, stirring, for about 1 minute to release the aromatics.
Add the water, cover, and simmer the chicken until cooked through, about 30 minutes. Transfer the chicken to a plate to cool and set the pan liquid aside.
Reduce the pan liquid over medium heat until reduced by half. Beat the eggs in a bowl and then pour them into the warm reduced liquid in a steady stream, stirring constantly until they form soft scrambled curds, about 3 minutes. Remove from heat and transfer the egg mixture to a bowl.
Discard the chicken skin. Remove the meat from the bones and shred it, then stir the shredded chicken into the egg mixture.
Grind the blanched almonds in a food processor to a coarse texture (nearly paste). Add the powdered sugar and ground cinnamon and pulse a couple of times, then fold the ground almonds into the chicken and egg mixture along with the orange flower water, lemon zest, lemon juice, chopped parsley, and chopped cilantro. Taste and season with salt and pepper as needed.
Preheat the oven to 375°F (190°C). Butter a 12-inch (30 cm) baking dish.
Unwrap the filo and keep it covered with a damp towel. Working quickly, lay one filo sheet in the dish lining the bottom and sides and brush with melted butter. Add three more sheets, brushing each with butter except the final one of this layer.
Spread the chicken and almond filling evenly in the dish. Fold the overhanging filo edges over the filling and brush exposed pastry with melted butter.
Top the filling with the remaining three sheets of filo, brushing each sheet with butter after placing it. Tuck or fold the edges neatly and trim if needed. Brush the top generously with butter.
Bake the basteeya for 30 to 40 minutes, until the top is well browned and crisp.
Remove from the oven and dust liberally with powdered sugar mixed with a generous pinch of cinnamon. Slice and serve warm.