from typing import Any
import api


############################################################
# ChangeSet
############################################################

API_ADD = api.API_ADD
API_UPDATE = api.API_UPDATE
API_DELETE = api.API_DELETE

ChangeSet = api.ChangeSet


############################################################
# enum
############################################################

JUNCTION = api.JUNCTION
RESERVOIR = api.RESERVOIR
TANK = api.TANK
PIPE = api.PIPE
PUMP = api.PUMP
VALVE = api.VALVE
PATTERN = api.PATTERN
CURVE = api.CURVE

OVERFLOW_YES = api.OVERFLOW_YES
OVERFLOW_NO = api.OVERFLOW_NO

PIPE_STATUS_OPEN = api.PIPE_STATUS_OPEN
PIPE_STATUS_CLOSED = api.PIPE_STATUS_CLOSED
PIPE_STATUS_CV = api.PIPE_STATUS_CV

VALVES_TYPE_PRV = api.VALVES_TYPE_PRV
VALVES_TYPE_PSV = api.VALVES_TYPE_PSV
VALVES_TYPE_PBV = api.VALVES_TYPE_PBV
VALVES_TYPE_FCV = api.VALVES_TYPE_FCV
VALVES_TYPE_TCV = api.VALVES_TYPE_TCV
VALVES_TYPE_GPV = api.VALVES_TYPE_GPV

LINK_STATUS_OPEN = api.LINK_STATUS_OPEN
LINK_STATUS_CLOSED = api.LINK_STATUS_CLOSED
LINK_STATUS_ACTIVE = api.LINK_STATUS_ACTIVE

TIME_STATISTIC_NONE = api.TIME_STATISTIC_NONE
TIME_STATISTIC_AVERAGED = api.TIME_STATISTIC_AVERAGED
TIME_STATISTIC_MINIMUM = api.TIME_STATISTIC_MINIMUM
TIME_STATISTIC_MAXIMUM = api.TIME_STATISTIC_MAXIMUM
TIME_STATISTIC_RANGE = api.TIME_STATISTIC_RANGE

OPTION_UNITS_CFS = api.OPTION_UNITS_CFS
OPTION_UNITS_GPM = api.OPTION_UNITS_GPM
OPTION_UNITS_MGD = api.OPTION_UNITS_MGD
OPTION_UNITS_IMGD = api.OPTION_UNITS_IMGD
OPTION_UNITS_AFD = api.OPTION_UNITS_AFD
OPTION_UNITS_LPS = api.OPTION_UNITS_LPS
OPTION_UNITS_LPM = api.OPTION_UNITS_LPM
OPTION_UNITS_MLD = api.OPTION_UNITS_MLD
OPTION_UNITS_CMH = api.OPTION_UNITS_CMH
OPTION_UNITS_CMD = api.OPTION_UNITS_CMD

OPTION_HEADLOSS_HW = api.OPTION_HEADLOSS_HW
OPTION_HEADLOSS_DW = api.OPTION_HEADLOSS_DW
OPTION_HEADLOSS_CM = api.OPTION_HEADLOSS_CM

OPTION_UNBALANCED_STOP = api.OPTION_UNBALANCED_STOP
OPTION_UNBALANCED_CONTINUE = api.OPTION_UNBALANCED_CONTINUE

OPTION_DEMAND_MODEL_DDA = api.OPTION_DEMAND_MODEL_DDA
OPTION_DEMAND_MODEL_PDA = api.OPTION_DEMAND_MODEL_PDA

OPTION_QUALITY_NONE = api.OPTION_QUALITY_NONE
OPTION_QUALITY_CHEMICAL = api.OPTION_QUALITY_CHEMICAL
OPTION_QUALITY_AGE = api.OPTION_QUALITY_AGE
OPTION_QUALITY_TRACE = api.OPTION_QUALITY_TRACE


############################################################
# project
############################################################

def have_project(name: str) -> bool:
    return api.have_project(name)

def create_project(name: str) -> None:
    return api.create_project(name)

def delete_project(name: str) -> None:
    return api.delete_project(name)

def is_project_open(name: str) -> bool:
    return api.is_project_open(name)

def get_project_open_count(name: str) -> int:
    return api.get_project_open_count(name)

def open_project(name: str) -> None:
    return api.open_project(name)

def close_project(name: str) -> None:
    return api.close_project(name)

def copy_project(source: str, new: str) -> None:
    return api.copy_project(source, new)

def read_inp(name: str, inp: str) -> None:
    return api.read_inp(name, inp)


############################################################
# operation
############################################################

def get_current_operation(name: str) -> int:
    return api.get_current_operation(name)

def execute_undo(name: str, discard: bool = False) -> ChangeSet:
    return api.execute_undo(name, discard)

def execute_redo(name: str) -> ChangeSet:
    return api.execute_redo(name)

def have_snapshot(name: str, tag: str) -> bool:
    return api.have_snapshot(name, tag)

def take_snapshot(name: str, tag: str) -> int | None:
    return api.take_snapshot(name, tag)

def pick_snapshot(name: str, tag: str, discard: bool = False) -> ChangeSet:
    return api.pick_snapshot(name, tag, discard)

def sync_with_server(name: str, operation: int) -> ChangeSet:
    return api.sync_with_server(name, operation)

def execute_batch_commands(name: str, cs: ChangeSet) -> ChangeSet:
    return api.execute_batch_commands(name, cs)


############################################################
# type
############################################################

def is_node(name: str, node_id: str) -> bool:
    return api.is_node(name, node_id)

def is_junction(name: str, node_id: str) -> bool:
    return api.is_junction(name, node_id)

def is_reservoir(name: str, node_id: str) -> bool:
    return api.is_reservoir(name, node_id)

def is_tank(name: str, node_id: str) -> bool:
    return api.is_tank(name, node_id)

def is_link(name: str, link_id: str) -> bool:
    return api.is_link(name, link_id)

def is_pipe(name: str, link_id: str) -> bool:
    return api.is_pipe(name, link_id)

def is_pump(name: str, link_id: str) -> bool:
    return api.is_pump(name, link_id)

def is_valve(name: str, link_id: str) -> bool:
    return api.is_valve(name, link_id)

def is_curve(name: str, curve_id: str) -> bool:
    return api.is_curve(name, curve_id)

def is_pattern(name: str, pattern_id: str) -> bool:
    return api.is_pattern(name, pattern_id)

def get_nodes(name: str) -> list[str]:
    return api.get_nodes(name)

def get_links(name: str) -> list[str]:
    return api.get_links(name)

def get_curves(name: str) -> list[str]:
    return api.get_curves(name)

def get_patterns(name: str) -> list[str]:
    return api.get_patterns(name)

def get_node_links(name: str, node_id: str) -> list[str]:
    return api.get_node_links(name, node_id)


############################################################
# title 1.[TITLE]
############################################################

def get_title_schema(name: str) -> dict[str, dict[str, Any]]:
    return api.get_title_schema(name)

def get_title(name: str) -> dict[str, Any]:
    return api.get_title(name)

def set_title(name: str, cs: ChangeSet) -> ChangeSet:
    return api.set_title(name, cs)


############################################################
# junction 2.[JUNCTIONS]
############################################################

def get_junction_schema(name: str) -> dict[str, dict[str, Any]]:
    return api.get_junction_schema(name)

def get_junction(name: str, id: str) -> dict[str, Any]:
    return api.get_junction(name, id)

def set_junction(name: str, cs: ChangeSet) -> ChangeSet:
    return api.set_junction(name, cs)

# example: add_junction(p, ChangeSet({'id': 'j0', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
def add_junction(name: str, cs: ChangeSet) -> ChangeSet:
    return api.add_junction(name, cs)

def delete_junction(name: str, cs: ChangeSet) -> ChangeSet:
    return api.delete_junction(name, cs)


############################################################
# reservoir 3.[RESERVOIRS]
############################################################

def get_reservoir_schema(name: str) -> dict[str, dict[str, Any]]:
    return api.get_reservoir_schema(name)

def get_reservoir(name: str, id: str) -> dict[str, Any]:
    return api.get_reservoir(name, id)

def set_reservoir(name: str, cs: ChangeSet) -> ChangeSet:
    return api.set_reservoir(name, cs)

# example: add_reservoir(p, ChangeSet({'id': 'r0', 'x': 0.0, 'y': 10.0, 'head': 20.0}))
def add_reservoir(name: str, cs: ChangeSet) -> ChangeSet:
    return api.add_reservoir(name, cs)

def delete_reservoir(name: str, cs: ChangeSet) -> ChangeSet:
    return api.delete_reservoir(name, cs)


############################################################
# tank 4.[TANKS]
############################################################

def get_tank_schema(name: str) -> dict[str, dict[str, Any]]:
    return api.get_tank_schema(name)

def get_tank(name: str, id: str) -> dict[str, Any]:
    return api.get_tank(name, id)

def set_tank(name: str, cs: ChangeSet) -> ChangeSet:
    return api.set_tank(name, cs)

# example: add_tank(p, ChangeSet({'id': 't0', 'x': 0.0, 'y': 10.0, 'elevation': 20.0, 'init_level': 1.0, 'min_level': 0.0, 'max_level': 2.0, 'diameter': 10.0, 'min_vol': 100.0}))
def add_tank(name: str, cs: ChangeSet) -> ChangeSet:
    return api.add_tank(name, cs)

def delete_tank(name: str, cs: ChangeSet) -> ChangeSet:
    return api.delete_tank(name, cs)


############################################################
# pipe 5.[PIPES]
############################################################

def get_pipe_schema(name: str) -> dict[str, dict[str, Any]]:
    return api.get_pipe_schema(name)

def get_pipe(name: str, id: str) -> dict[str, Any]:
    return api.get_pipe(name, id)

def set_pipe(name: str, cs: ChangeSet) -> ChangeSet:
    return api.set_pipe(name, cs)

# example: add_pipe(p, ChangeSet({'id': 'p0', 'node1': 'j1', 'node2': 'j2', 'length': 100.0, 'diameter': 10.0, 'roughness': 0.1, 'minor_loss': 0.5, 'status': PIPE_STATUS_OPEN }))
def add_pipe(name: str, cs: ChangeSet) -> ChangeSet:
    return api.add_pipe(name, cs)

def delete_pipe(name: str, cs: ChangeSet) -> ChangeSet:
    return api.delete_pipe(name, cs)


############################################################
# pump 6.[PUMPS]
############################################################

def get_pump_schema(name: str) -> dict[str, dict[str, Any]]:
    return api.get_pump_schema(name)

def get_pump(name: str, id: str) -> dict[str, Any]:
    return api.get_pump(name, id)

def set_pump(name: str, cs: ChangeSet) -> ChangeSet:
    return api.set_pump(name, cs)

# example: add_pump(p, ChangeSet({'id': 'p0', 'node1': 'j1', 'node2': 'j2', 'power': 0}))
def add_pump(name: str, cs: ChangeSet) -> ChangeSet:
    return api.add_pump(name, cs)

def delete_pump(name: str, cs: ChangeSet) -> ChangeSet:
    return api.delete_pump(name, cs)


############################################################
# valve 7.[VALVES]
############################################################

def get_valve_schema(name: str) -> dict[str, dict[str, Any]]:
    return api.get_valve_schema(name)

def get_valve(name: str, id: str) -> dict[str, Any]:
    return api.get_valve(name, id)

def set_valve(name: str, cs: ChangeSet) -> ChangeSet:
    return api.set_valve(name, cs)

#example: add_valve(p, ChangeSet({'id': 'v0', 'node1': 'j1', 'node2': 'j2', 'diameter': 10.0, 'v_type': VALVES_TYPE_FCV, 'setting': 0.1, 'minor_loss': 0.5 }))
def add_valve(name: str, cs: ChangeSet) -> ChangeSet:
    return api.add_valve(name, cs)

def delete_valve(name: str, cs: ChangeSet) -> ChangeSet:
    return api.delete_valve(name, cs)


############################################################
# demand 9.[DEMANDS]
############################################################

def get_demand_schema(name: str) -> dict[str, dict[str, Any]]:
    return api.get_demand_schema(name)

def get_demand(name: str, junction: str) -> dict[str, Any]:
    return api.get_demand(name, junction)

# { 'operation': 'update', 'type': 'demand', 'junction': 'j1', 'demands': [{'demand': 0.0, 'patten': None, 'category': None}] }
def set_demand(name: str, cs: ChangeSet) -> ChangeSet:
    return api.set_demand(name, cs)


############################################################
# status 10.[STATUS]
############################################################

def get_status_schema(name: str) -> dict[str, dict[str, Any]]:
    return api.get_status_schema(name)

def get_status(name: str, link: str) -> dict[str, Any]:
    return api.get_status(name, link)

def set_status(name: str, cs: ChangeSet) -> ChangeSet:
    return api.set_status(name, cs)


############################################################
# pattern 11.[PATTERNS]
############################################################

def get_pattern_schema(name: str) -> dict[str, dict[str, Any]]:
    return api.get_pattern_schema(name)

def get_pattern(name: str, id: str) -> dict[str, Any]:
    return api.get_pattern(name, id)

def set_pattern(name: str, cs: ChangeSet) -> ChangeSet:
    return api.set_pattern(name, cs)


############################################################
# curve 12.[CURVES]
############################################################

def get_curve_schema(name: str) -> dict[str, dict[str, Any]]:
    return api.get_curve_schema(name)

def get_curve(name: str, id: str) -> dict[str, Any]:
    return api.get_curve(name, id)

def set_curve(name: str, cs: ChangeSet) -> ChangeSet:
    return api.set_curve(name, cs)


############################################################
# emitter 16.[EMITTERS]
############################################################

def get_emitter_schema(name: str) -> dict[str, dict[str, Any]]:
    return api.get_emitter_schema(name)

def get_emitter(name: str, junction: str) -> dict[str, Any]:
    return api.get_emitter(name, junction)

def set_emitter(name: str, cs: ChangeSet) -> ChangeSet:
    return api.set_emitter(name, cs)


############################################################
# time 21.[EMITTERS]
############################################################

def get_time_schema(name: str) -> dict[str, dict[str, Any]]:
    return api.get_time_schema(name)

def get_time(name: str) -> dict[str, Any]:
    return api.get_time(name)

def set_time(name: str, cs: ChangeSet) -> ChangeSet:
    return api.set_time(name, cs)


############################################################
# option 23.[OPTIONS]
############################################################

def get_option_schema(name: str) -> dict[str, dict[str, Any]]:
    return api.get_option_schema(name)

def get_option(name: str) -> dict[str, Any]:
    return api.get_option(name)

def set_option(name: str, cs: ChangeSet) -> ChangeSet:
    return api.set_option(name, cs)


############################################################
# coord 24.[COORDINATES]
############################################################

def get_node_coord(name: str, node_id: str) -> dict[str, float] | None:
    return api.get_node_coord(name, node_id)
