You are given feature definitions and a user's runtime information. Each feature definition contains:
- countries: the list of allowed countries
- min_version: the minimum OS version required
- dependencies: other features that must be enabled first
A requested feature can be enabled if:
1. The user's country is in that feature's allowed countries.
2. The user's OS version is at least the feature's min_version.
3. Every dependency is already in pre_enabled, or can itself be enabled by the same rules.
4. Dependency resolution does not encounter a cycle.
If a dependency name does not exist in the feature definitions, treat that dependency as invalid.
Return the requested features that can be enabled, in the same order they appear in requested. Auto-enabled dependencies should not be included in the result unless they were explicitly requested.
Important: Features listed in pre_enabled are treated as already active and satisfy dependency checks immediately.
Examples
Input: ({'core': {'countries': ['US', 'CA'], 'min_version': 1, 'dependencies': []}, 'chat': {'countries': ['US'], 'min_version': 2, 'dependencies': ['core']}, 'video': {'countries': ['US'], 'min_version': 3, 'dependencies': ['chat']}}, 'US', 3, [], ['chat', 'video'])
Expected Output: ['chat', 'video']
Explanation: 'core' can be enabled automatically, so both requested features are valid.
Input: ({'core': {'countries': ['US', 'CA'], 'min_version': 1, 'dependencies': []}, 'chat': {'countries': ['US'], 'min_version': 2, 'dependencies': ['core']}, 'pay': {'countries': ['GB'], 'min_version': 4, 'dependencies': []}}, 'US', 3, [], ['chat', 'pay'])
Expected Output: ['chat']
Explanation: 'chat' is valid. 'pay' is invalid because the user is not in an allowed country and also does not meet the minimum OS version.
Input: ({'A': {'countries': ['US'], 'min_version': 1, 'dependencies': ['B']}, 'B': {'countries': ['US'], 'min_version': 1, 'dependencies': ['A']}, 'C': {'countries': ['US'], 'min_version': 1, 'dependencies': []}}, 'US', 1, [], ['A', 'C'])
Expected Output: ['C']
Explanation: 'A' and 'B' form a cycle, so 'A' cannot be enabled. 'C' has no dependencies and is valid.
Input: ({'auth': {'countries': ['CA'], 'min_version': 10, 'dependencies': []}, 'dashboard': {'countries': ['US'], 'min_version': 1, 'dependencies': ['auth']}}, 'US', 1, ['auth'], ['dashboard'])
Expected Output: ['dashboard']
Explanation: 'auth' is already pre-enabled, so it satisfies the dependency immediately.
Input: ({'base': {'countries': ['US'], 'min_version': 1, 'dependencies': []}}, 'US', 5, [], [])
Expected Output: []
Explanation: With no requested features, the result is empty.