Multi-level Energy Management Framework with Flexibility Provision in Distribution Networks