from typing import List, Any
from fastapi import APIRouter, Request, HTTPException
from app.services.tjnetwork import (
    ChangeSet,
    get_all_extension_data_keys,
    get_all_extension_data,
    get_extension_data,
    set_extension_data
)

router = APIRouter()

@router.get("/getallextensiondatakeys/")
async def get_all_extension_data_keys_endpoint(network: str) -> list[str]:
    return get_all_extension_data_keys(network)

@router.get("/getallextensiondata/")
async def get_all_extension_data_endpoint(network: str) -> dict[str, Any]:
    return get_all_extension_data(network)

@router.get("/getextensiondata/")
async def get_extension_data_endpoint(network: str, key: str) -> str | None:
    return get_extension_data(network, key)

@router.post("/setextensiondata/", response_model=None)
async def set_extension_data_endpoint(network: str, req: Request) -> ChangeSet:
    props = await req.json()
    print(props)
    cs = set_extension_data(network, ChangeSet(props))
    print(cs.operations[0])
    return cs
