# Copyright (c) Huawei Technologies Co., Ltd. 2026-2026. All rights reserved.
# OpenOLC is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#         `http://license.coscl.org.cn/MulanPSL2`
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.

import threading

# 服务名
ServiceName = "ServiceName"

# 接口名
InterfaceName = "InterfaceName"

URL = "URL"

Method = "Method"

# IP
IP = "IP"

Tenant = "Tenant"

# model
Model = "Model"

UserPriority = "UserPriority"

UUID = "UUID"

Resource = "Resource"

ENV = "ENV"

TenantLevel = "TenantLevel"

Priority = "Priority"


class Dimension(threading.Thread):
    _instance = None
    _lock = threading.Lock()

    def __init__(self):
        super().__init__()
        self.dimension = {}
        self.init()

    def init(self):
        self.dimension[ServiceName] = True
        self.dimension[InterfaceName] = True
        self.dimension[IP] = True
        self.dimension[Model] = True
        self.dimension[Tenant] = True
        self.dimension[URL] = True
        self.dimension[Method] = True
        self.dimension[TenantLevel] = True
        self.dimension[Priority] = True
        self.dimension[UUID] = True
        self.dimension[Resource] = True
        self.dimension[ENV] = True
        self.dimension[UserPriority] = True

    def get_dimension(self, dimension: str) -> bool:
        return self.dimension.get(dimension, False)

    def get_available_dimensions(self) -> list:
        return list(self.dimension.keys())

    @classmethod
    def get_instance(cls) -> 'Dimension':
        if cls._instance is None:
            with cls._lock:
                if cls._instance is None:
                    cls._instance = cls()
        return cls._instance

    def __repr__(self):
        return f"Dimension(available_dimensions={list(self.dimension.keys())})"

    def __str__(self):
        return self.__repr__()