from fastapi import APIRouter, Request
from typing import Any, List, Dict, Union
from app.services.tjnetwork import (
    Any,
    ChangeSet,
    get_energy,
    get_energy_schema,
    get_option_v3,
    get_option_v3_schema,
    get_pump_energy,
    get_pump_energy_schema,
    get_time,
    get_time_schema,
    set_energy,
    set_option_v3,
    set_pump_energy,
    set_time,
)

router = APIRouter()

@router.get("/gettimeschema")
async def fastapi_get_time_schema(network: str) -> dict[str, dict[str, Any]]:
    return get_time_schema(network)

@router.get("/gettimeproperties/")
async def fastapi_get_time_properties(network: str) -> dict[str, Any]:
    return get_time(network)

@router.post("/settimeproperties/", response_model=None)
async def fastapi_set_time_properties(network: str, req: Request) -> ChangeSet:
    props = await req.json()
    return set_time(network, ChangeSet(props))

@router.get("/getenergyschema/")
async def fastapi_get_energy_schema(network: str) -> dict[str, dict[str, Any]]:
    return get_energy_schema(network)

@router.get("/getenergyproperties/")
async def fastapi_get_energy_properties(network: str) -> dict[str, Any]:
    return get_energy(network)

@router.post("/setenergyproperties/", response_model=None)
async def fastapi_set_energy_properties(network: str, req: Request) -> ChangeSet:
    props = await req.json()
    return set_energy(network, ChangeSet(props))

@router.get("/getpumpenergyschema/")
async def fastapi_get_pump_energy_schema(network: str) -> dict[str, dict[str, Any]]:
    return get_pump_energy_schema(network)

@router.get("/getpumpenergyproperties//")
async def fastapi_get_pump_energy_proeprties(network: str, pump: str) -> dict[str, Any]:
    return get_pump_energy(network, pump)

@router.get("/setpumpenergyproperties//", response_model=None)
async def fastapi_set_pump_energy_properties(
    network: str, pump: str, req: Request
) -> ChangeSet:
    props = await req.json()
    ps = {"id": pump} | props
    return set_pump_energy(network, ChangeSet(ps))

@router.get("/getoptionschema/")
async def fastapi_get_option_schema(network: str) -> dict[str, dict[str, Any]]:
    return get_option_v3_schema(network)

@router.get("/getoptionproperties/")
async def fastapi_get_option_properties(network: str) -> dict[str, Any]:
    return get_option_v3(network)

@router.post("/setoptionproperties/", response_model=None)
async def fastapi_set_option_properties(network: str, req: Request) -> ChangeSet:
    props = await req.json()
    return set_option_v3(network, ChangeSet(props))
