from enum import Enum, auto
from typing import Tuple


class SoftwareCategory(Enum):
    """软件大类"""

    MAIN_GRID = "主网"  # 主网
    DISTRIBUTION = "配网"  # 配网
    TECHNICAL_RENOVATION = "技改"  # 技改


class EngineeringType(Enum):
    """工程类型"""

    BUDGET = "预算"  # 预算工程
    BILL = "清单"  # 清单工程


class SoftwareType:
    """软件类型"""

    def __init__(self, category: SoftwareCategory, engineering_type: EngineeringType):
        self.category = category
        self.engineering_type = engineering_type

    @property
    def name(self) -> str:
        """获取软件类型名称"""
        return f"{self.category.value}{self.engineering_type.value}"

    @property
    def config_dir(self) -> str:
        """获取配置目录"""
        return f"计算配置/{self.category.value}/{self.name}"

    @property
    def test_dir(self) -> str:
        """获取测试案例目录"""
        return f"测试案例/{self.category.value}/{self.engineering_type.value}"

    def __str__(self) -> str:
        return self.name

    def __repr__(self) -> str:
        return f"SoftwareType({self.category.value}, {self.engineering_type.value})"


# 预定义的六种软件类型
MAIN_GRID_BUDGET = SoftwareType(SoftwareCategory.MAIN_GRID, EngineeringType.BUDGET)
MAIN_GRID_BILL = SoftwareType(SoftwareCategory.MAIN_GRID, EngineeringType.BILL)
DISTRIBUTION_BUDGET = SoftwareType(SoftwareCategory.DISTRIBUTION, EngineeringType.BUDGET)
DISTRIBUTION_BILL = SoftwareType(SoftwareCategory.DISTRIBUTION, EngineeringType.BILL)
TECHNICAL_RENOVATION_BUDGET = SoftwareType(SoftwareCategory.TECHNICAL_RENOVATION, EngineeringType.BUDGET)
TECHNICAL_RENOVATION_BILL = SoftwareType(SoftwareCategory.TECHNICAL_RENOVATION, EngineeringType.BILL)

# 所有软件类型列表
ALL_SOFTWARE_TYPES = [
    MAIN_GRID_BUDGET,
    MAIN_GRID_BILL,
    DISTRIBUTION_BUDGET,
    DISTRIBUTION_BILL,
    TECHNICAL_RENOVATION_BUDGET,
    TECHNICAL_RENOVATION_BILL,
]


def get_software_type(category_name: str, engineering_type_name: str) -> SoftwareType:
    """
    根据类别名称和工程类型名称获取软件类型

    Args:
        category_name: 类别名称（主网/配网/技改）
        engineering_type_name: 工程类型名称（预算/清单）

    Returns:
        SoftwareType: 软件类型
    """
    try:
        category = SoftwareCategory(category_name)
        eng_type = EngineeringType(engineering_type_name)
        return SoftwareType(category, eng_type)
    except ValueError:
        valid_categories = [c.value for c in SoftwareCategory]
        valid_eng_types = [t.value for t in EngineeringType]
        raise ValueError(
            f"无效的软件类型: {category_name}/{engineering_type_name}. "
            f"有效的类别: {valid_categories}, 有效的工程类型: {valid_eng_types}"
        )
