#! /usr/bin/env python
# _*_ coding: utf-8 _*_
"""
author:
date:       2023/12/11
file:       agents.py
version:
doc:        解析前端配置文件, 实例化前端配置的智能体类.

"""
import importlib
import os

from corekit.hikframe.rl.layout import layout_config


def get_agents():
    agents = []
    layout_groups = layout_config.get("groups", [])  # list[dict]
    for group in layout_groups:
        if group.get("connected") is False:
            continue
        group_side: str = group["side"]
        if group_side == "红方":
            group_side = "RED"
        elif group_side == "蓝方":
            group_side = "BLUE"

        group_agents = group["agents"]  # list[dict]
        for agent in group_agents:
            agent_id = agent["id"]
            agent_path = agent["file_path"]
            agent_name = os.path.basename(agent_path)
            agent_module = "hiklayout.{}".format(agent_id)
            agent_obj = importlib.import_module(agent_module).Agent(agent_id, group_side)
            agents.append(agent_obj)
    return agents
