If using fresh cod, pat the fillets dry and check for any remaining bones. Cut the fish into large portions. If using salted cod, make sure it has been thoroughly desalted and drained. Season lightly with black pepper, lemon juice, and a little paprika if desired.
Peel the potatoes and cut them into approximately ½-centimeter-thick slices. Place them in boiling water and cook for 6–8 minutes, until they begin to soften but are not falling apart. Drain and set aside.
Heat the olive oil in a large skillet over medium-low heat. Add the sliced onions and cook for 6–8 minutes until softened and lightly golden. Stir in the chopped garlic and optional bay leaf, cooking for another minute. Avoid browning the garlic too much, as it can become bitter.
Preheat the oven to 190°C (375°F). Lightly grease a baking dish with olive oil. Arrange half the potatoes across the bottom, followed by some of the onion mixture. Place the cod pieces on top, then add the remaining potatoes and onions. Scatter the black olives over the casserole and drizzle the remaining olive oil evenly across the ingredients.
Pour a small amount of fish stock or water around the sides of the dish if the mixture looks dry. Taste the onion mixture before adding any extra salt, especially when using salted cod. Cover the casserole loosely with foil to help the potatoes and fish cook evenly.
Bake for approximately 25 minutes. Remove the foil and continue baking for another 10–15 minutes, until the potatoes are tender, the fish flakes easily, and the top is lightly golden. Cooking time may vary depending on the thickness of the cod and potatoes.
Remove the casserole from the oven and let it rest for 5 minutes. Sprinkle freshly chopped parsley over the top and add a little lemon juice. Serve warm with lemon wedges, a fresh salad, or crusty bread to soak up the flavorful olive oil.