"""Cluster class."""
from generator.utils import create_sub_element
from generator.maps.sector import Sector


class Cluster:
    def __init__(self, prefix, cluster):
        self.id = cluster["id"]
        self.x = cluster["x"]
        self.y = 0
        self.z = cluster["z"]
        self.name = cluster.get("name", f"CLUSTER{self.id:03}")
        self.description = cluster.get("description", "UNKNOWN")
        self.encyclopedia = cluster.get("encyclopedia", {})
        if "system" in cluster.keys():
            self.system = cluster["system"]
        self.environment = cluster.get("environment", None)
        self.internal_name = f"{prefix}_cluster{self.id:03}"

        self.sectors = self._add_sectors(cluster["sectors"])

    def __getitem__(self, key):
        matching_sector = None
        for sector in self.sectors:
            if sector.id == key:
                matching_sector = sector
                break
        return matching_sector

    @property
    def connection_ref(self):
        return f"{self.internal_name}_connection"

    @property
    def macro_ref(self):
        return f"{self.internal_name}_macro"

    def get_cluster_connections(self):
        connections = {}
        for sector in self.sectors:
            connections.update(sector.gates)
        return connections

    def _add_sectors(self, sectors):
        created_sectors = []
        for sector in sectors:
            created_sectors.append(Sector(sector, self.id, self.internal_name))
        return created_sectors

86546e2dcd16e2ba65b200d5fab95c6c675facb1
<mask token>


class Cluster:
    <mask token>
    <mask token>
    <mask token>

    @property
    def macro_ref(self):
        return f'{self.internal_name}_macro'

    def get_cluster_connections(self):
        connections = {}
        for sector in self.sectors:
            connections.update(sector.gates)
        return connections

    def _add_sectors(self, sectors):
        created_sectors = []
        for sector in sectors:
            created_sectors.append(Sector(sector, self.id, self.internal_name))
        return created_sectors

<mask token>


class Cluster:

    def __init__(self, prefix, cluster):
        self.id = cluster['id']
        self.x = cluster['x']
        self.y = 0
        self.z = cluster['z']
        self.name = cluster.get('name', f'CLUSTER{self.id:03}')
        self.description = cluster.get('description', 'UNKNOWN')
        self.encyclopedia = cluster.get('encyclopedia', {})
        if 'system' in cluster.keys():
            self.system = cluster['system']
        self.environment = cluster.get('environment', None)
        self.internal_name = f'{prefix}_cluster{self.id:03}'
        self.sectors = self._add_sectors(cluster['sectors'])
    <mask token>

    @property
    def connection_ref(self):
        return f'{self.internal_name}_connection'

    @property
    def macro_ref(self):
        return f'{self.internal_name}_macro'

    def get_cluster_connections(self):
        connections = {}
        for sector in self.sectors:
            connections.update(sector.gates)
        return connections

    def _add_sectors(self, sectors):
        created_sectors = []
        for sector in sectors:
            created_sectors.append(Sector(sector, self.id, self.internal_name))
        return created_sectors

<mask token>


class Cluster:

    def __init__(self, prefix, cluster):
        self.id = cluster['id']
        self.x = cluster['x']
        self.y = 0
        self.z = cluster['z']
        self.name = cluster.get('name', f'CLUSTER{self.id:03}')
        self.description = cluster.get('description', 'UNKNOWN')
        self.encyclopedia = cluster.get('encyclopedia', {})
        if 'system' in cluster.keys():
            self.system = cluster['system']
        self.environment = cluster.get('environment', None)
        self.internal_name = f'{prefix}_cluster{self.id:03}'
        self.sectors = self._add_sectors(cluster['sectors'])

    def __getitem__(self, key):
        matching_sector = None
        for sector in self.sectors:
            if sector.id == key:
                matching_sector = sector
                break
        return matching_sector

    @property
    def connection_ref(self):
        return f'{self.internal_name}_connection'

    @property
    def macro_ref(self):
        return f'{self.internal_name}_macro'

    def get_cluster_connections(self):
        connections = {}
        for sector in self.sectors:
            connections.update(sector.gates)
        return connections

    def _add_sectors(self, sectors):
        created_sectors = []
        for sector in sectors:
            created_sectors.append(Sector(sector, self.id, self.internal_name))
        return created_sectors

<mask token>
from generator.utils import create_sub_element
from generator.maps.sector import Sector


class Cluster:

    def __init__(self, prefix, cluster):
        self.id = cluster['id']
        self.x = cluster['x']
        self.y = 0
        self.z = cluster['z']
        self.name = cluster.get('name', f'CLUSTER{self.id:03}')
        self.description = cluster.get('description', 'UNKNOWN')
        self.encyclopedia = cluster.get('encyclopedia', {})
        if 'system' in cluster.keys():
            self.system = cluster['system']
        self.environment = cluster.get('environment', None)
        self.internal_name = f'{prefix}_cluster{self.id:03}'
        self.sectors = self._add_sectors(cluster['sectors'])

    def __getitem__(self, key):
        matching_sector = None
        for sector in self.sectors:
            if sector.id == key:
                matching_sector = sector
                break
        return matching_sector

    @property
    def connection_ref(self):
        return f'{self.internal_name}_connection'

    @property
    def macro_ref(self):
        return f'{self.internal_name}_macro'

    def get_cluster_connections(self):
        connections = {}
        for sector in self.sectors:
            connections.update(sector.gates)
        return connections

    def _add_sectors(self, sectors):
        created_sectors = []
        for sector in sectors:
            created_sectors.append(Sector(sector, self.id, self.internal_name))
        return created_sectors

"""Cluster class."""
from generator.utils import create_sub_element
from generator.maps.sector import Sector


class Cluster:
    def __init__(self, prefix, cluster):
        self.id = cluster["id"]
        self.x = cluster["x"]
        self.y = 0
        self.z = cluster["z"]
        self.name = cluster.get("name", f"CLUSTER{self.id:03}")
        self.description = cluster.get("description", "UNKNOWN")
        self.encyclopedia = cluster.get("encyclopedia", {})
        if "system" in cluster.keys():
            self.system = cluster["system"]
        self.environment = cluster.get("environment", None)
        self.internal_name = f"{prefix}_cluster{self.id:03}"

        self.sectors = self._add_sectors(cluster["sectors"])

    def __getitem__(self, key):
        matching_sector = None
        for sector in self.sectors:
            if sector.id == key:
                matching_sector = sector
                break
        return matching_sector

    @property
    def connection_ref(self):
        return f"{self.internal_name}_connection"

    @property
    def macro_ref(self):
        return f"{self.internal_name}_macro"

    def get_cluster_connections(self):
        connections = {}
        for sector in self.sectors:
            connections.update(sector.gates)
        return connections

    def _add_sectors(self, sectors):
        created_sectors = []
        for sector in sectors:
            created_sectors.append(Sector(sector, self.id, self.internal_name))
        return created_sectors
