from fastapi import APIRouter, Request, Query, Path, Body
from typing import Any, List, Dict, Union
from app.services.tjnetwork import (
    Any,
    ChangeSet,
    get_tag,
    get_tag_schema,
    get_tags,
    set_tag,
)

router = APIRouter()

############################################################
# tag 8.[TAGS]
############################################################

@router.get(
    "/gettagschema/",
    summary="获取标签属性架构",
    description="获取指定水网的标签(Tag)属性架构定义"
)
async def fastapi_get_tag_schema(
    network: str = Query(..., description="管网名称（或数据库名称）")
) -> dict[str, dict[str, Any]]:
    """获取标签的属性架构。"""
    return get_tag_schema(network)

@router.get(
    "/gettag/",
    summary="获取标签信息",
    description="获取指定类型和ID的标签信息"
)
async def fastapi_get_tag(
    network: str = Query(..., description="管网名称（或数据库名称）"),
    t_type: str = Query(..., description="标签类型"),
    id: str = Query(..., description="元素ID")
) -> dict[str, Any]:
    """获取标签信息。"""
    return get_tag(network, t_type, id)

@router.get(
    "/gettags/",
    summary="获取所有标签",
    description="获取指定水网中的所有标签信息"
)
async def fastapi_get_tags(
    network: str = Query(..., description="管网名称（或数据库名称）")
) -> list[dict[str, Any]]:
    """获取水网中所有标签的列表。"""
    tags = get_tags(network)
    return tags

@router.post(
    "/settag/",
    response_model=None,
    summary="设置标签",
    description="为指定元素设置或修改标签信息"
)
async def fastapi_set_tag(
    network: str = Query(..., description="管网名称（或数据库名称）"),
    req: Request = None
) -> ChangeSet:
    """设置标签信息。"""
    props = await req.json()
    return set_tag(network, ChangeSet(props))
