from dask_gateway_server.options import Options, Select, Mapping

# A mapping from profile name to configuration overrides
profiles = {{ cookiecutter.profiles.dask_worker }}
environments = [
{% for filename, config in cookiecutter.environments.items() %}
    "{{config['name']}}",
{% endfor %}
]

def worker_profile(options):
    config = profiles[options.profile]
    config['worker_cmd'] = '/opt/conda-run-worker'
    config['scheduler_cmd'] = '/opt/conda-run-scheduler'
    config['environment'] = {
        **options.environment_vars,
        'CONDA_ENVIRONMENT': options.conda_environment
    }
    return config

# Expose a list of profiles for workers
c.Backend.cluster_options = Options(
    Select(
        "conda_environment",
        environments,
        default=environments[0],
        label='Environment',
    ),
    Select(
        "profile",
        {{ cookiecutter.profiles.dask_worker.keys() | list() }},
        default='{{ cookiecutter.profiles.dask_worker.keys() | list() | first() }}',
        label="Cluster Profile",
    ),
    Mapping("environment_vars", {}, label="Environment Variables"),
    handler=worker_profile,
)
