from __future__ import annotations

from dataclasses import dataclass
from typing import List, Optional


@dataclass(frozen=True)
class RegionPlan:
    """云地区执行计划，华为云和火山云都会复用这个轻量模型。"""
    key: str
    label: str
    region: str
    aux_count: int
    aux_start_octet: int
    standard_nic_count: int = 1
    virtual_ip_count: int = 0
    virtual_ip_start_octet: int = 0
    aux_parent_primary: bool = False


@dataclass(frozen=True)
class ProjectPair:
    """华为云 region 和 project_id 的绑定关系。"""
    region: str
    project_id: str


@dataclass
class RegionBuildResult:
    """单个地区搭建完成后的结果数据。"""
    plan: RegionPlan
    server_id: str
    server_ip: str
    password: str
    ip_txt: str
    public_ips: List[str]
    root_volume_type: str
    script_exit_code: int
    socks_user: str = ""
    socks_password: str = ""
    socks_port: str = ""
    l2tp_password: str = ""
    l2tp_psk: str = ""


class CloudApiError(RuntimeError):
    """云接口统一异常，保留 HTTP 状态码和原始响应体便于中文化提示。"""

    def __init__(self, message: str, status: Optional[int] = None, body: str = ""):
        super().__init__(message)
        self.status = status
        self.body = body
