# Copyright 2025 The RLinf Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from omegaconf import DictConfig

from rlinf.scheduler.worker.worker import Worker


def get_actor_worker(cfg: DictConfig) -> type[Worker]:
    if cfg.actor.training_backend == "fsdp":
        if cfg.runner.get("task_type", None) == "embodied" and cfg.runner.get(
            "use_training_pipeline", False
        ):
            if cfg.algorithm.loss_type in {
                "embodied_sac",
                "embodied_dagger",
                "embodied_nft",
            }:
                raise ValueError(
                    "runner.use_training_pipeline=True is not supported for "
                    f"loss_type={cfg.algorithm.loss_type}."
                )
            from .fsdp_actor_worker_pipeline import PipelineEmbodiedFSDPActor

            return PipelineEmbodiedFSDPActor
        from .fsdp_actor_worker import FSDPActor

        return FSDPActor
    elif cfg.actor.training_backend == "megatron":
        from .megatron_actor_worker import MegatronActor

        return MegatronActor
    else:
        raise ValueError(f"Unsupported training backend: {cfg.actor.training_backend}")
