"""`app.native.wndb` 的公共 API 门面。

调用建议：
- 推荐使用模块方式导入，保持调用点清晰：
        `import app.native.wndb as wndb`
- 典型流程：
        1) 项目生命周期：`open_project(...)` / `close_project(...)`
        2) 模型数据读写：`get_*`, `set_*`, `add_*`, `delete_*`
        3) 持久化与恢复：`take_snapshot(...)`, `execute_undo()`, `restore(...)`

该文件刻意保持平铺导出，以兼容历史调用。
"""

# -----------------------------------------------------------------------------
# 项目生命周期与 INP 导入导出
# -----------------------------------------------------------------------------
from .project import (
    list_project,
    have_project,
    create_project,
    delete_project,
    clean_project,
)
from .project import is_project_open, open_project, close_project
from .project import copy_project

# DingZQ, 2024-12-28: 将 INP v3 转换为 v2
from .inp_in import read_inp, import_inp, convert_inp_v3_to_v2
from .inp_out import dump_inp, export_inp

# -----------------------------------------------------------------------------
# 数据库操作、快照与撤销重做
# -----------------------------------------------------------------------------
from .database import API_ADD, API_UPDATE, API_DELETE
from .database import ChangeSet
from .database import get_current_operation
from .database import execute_undo, execute_redo
from .database import list_snapshot
from .database import (
    have_snapshot,
    have_snapshot_for_operation,
    have_snapshot_for_current_operation,
)
from .database import (
    take_snapshot_for_operation,
    take_snapshot_for_current_operation,
    take_snapshot,
)
from .database import update_snapshot, update_snapshot_for_current_operation
from .database import delete_snapshot, delete_snapshot_by_operation
from .database import get_operation_by_snapshot, get_snapshot_by_operation
from .database import pick_snapshot
from .database import pick_operation, sync_with_server
from .database import (
    get_restore_operation,
    set_restore_operation,
    set_restore_operation_to_current,
    restore,
)
from .database import read, try_read, read_all, write

# -----------------------------------------------------------------------------
# 批处理执行与扩展数据
# -----------------------------------------------------------------------------
from .batch_exe import execute_batch_commands, execute_batch_command

from .extension_data import (
    get_all_extension_data_keys,
    get_all_extension_data,
    get_extension_data,
    set_extension_data,
)

# -----------------------------------------------------------------------------
# 核心网络模型基础类型与辅助方法
# -----------------------------------------------------------------------------
from .s0_base import JUNCTION, RESERVOIR, TANK, PIPE, PUMP, VALVE, PATTERN, CURVE
from .s0_base import is_node, is_junction, is_reservoir, is_tank
from .s0_base import is_link, is_pipe, is_pump, is_valve
from .s0_base import is_curve
from .s0_base import is_pattern
from .s0_base import (
    get_nodes,
    get_nodes_id_and_type,
    get_junctions,
    get_reservoirs,
    get_tanks,
    get_links,
    get_links_id_and_type,
    get_pipes,
    get_pumps,
    get_valves,
    get_curves,
    get_patterns,
)
from .s0_base import (
    get_node_type,
    get_link_type,
    get_element_type,
    get_element_type_value,
)
from .s0_base import get_node_links, get_link_nodes
from .s0_base import get_major_nodes, get_major_pipes

# -----------------------------------------------------------------------------
# EPANET 基础分段（S1-S27）
# -----------------------------------------------------------------------------
from .s1_title import get_title_schema, get_title, set_title

from .s2_junctions import (
    get_junction_schema,
    add_junction,
    get_junction,
    set_junction,
    get_all_junctions,
)
from .batch_api import delete_junction_cascade

from .s3_reservoirs import (
    get_reservoir_schema,
    add_reservoir,
    get_reservoir,
    set_reservoir,
    get_all_reservoirs,
)
from .batch_api import delete_reservoir_cascade

from .s4_tanks import OVERFLOW_YES, OVERFLOW_NO
from .s4_tanks import get_tank_schema, add_tank, get_tank, set_tank, get_all_tanks
from .batch_api import delete_tank_cascade

from .s5_pipes import PIPE_STATUS_OPEN, PIPE_STATUS_CLOSED, PIPE_STATUS_CV
from .s5_pipes import (
    get_pipe_schema,
    add_pipe,
    get_pipe,
    set_pipe,
    get_all_pipes,
    get_pipes_by_property,
)
from .batch_api import delete_pipe_cascade

from .s6_pumps import get_pump_schema, add_pump, get_pump, set_pump, get_all_pumps
from .batch_api import delete_pump_cascade

from .s7_valves import (
    VALVES_TYPE_PRV,
    VALVES_TYPE_PSV,
    VALVES_TYPE_PBV,
    VALVES_TYPE_FCV,
    VALVES_TYPE_TCV,
    VALVES_TYPE_GPV,
)
from .s7_valves import get_valve_schema, add_valve, get_valve, set_valve, get_all_valves
from .batch_api import delete_valve_cascade

from .s8_tags import TAG_TYPE_NODE, TAG_TYPE_LINK
from .s8_tags import get_tag_schema, get_tags, get_tag, set_tag

from .s9_demands import get_demand_schema, get_demand, set_demand

from .s10_status import LINK_STATUS_OPEN, LINK_STATUS_CLOSED, LINK_STATUS_ACTIVE
from .s10_status import get_status_schema, get_status, set_status

from .s11_patterns import get_pattern_schema, get_pattern, set_pattern, add_pattern
from .batch_api import delete_pattern_cascade

from .s12_curves import (
    CURVE_TYPE_PUMP,
    CURVE_TYPE_EFFICIENCY,
    CURVE_TYPE_VOLUME,
    CURVE_TYPE_HEADLOSS,
)
from .s12_curves import get_curve_schema, get_curve, set_curve, add_curve
from .batch_api import delete_curve_cascade

from .s13_controls import get_control_schema, get_control, set_control

from .s14_rules import get_rule_schema, get_rule, set_rule

from .s15_energy import get_energy_schema, get_energy, set_energy
from .s15_energy import get_pump_energy_schema, get_pump_energy, set_pump_energy

from .s16_emitters import get_emitter_schema, get_emitter, set_emitter

from .s17_quality import get_quality_schema, get_quality, set_quality

from .s18_sources import (
    SOURCE_TYPE_CONCEN,
    SOURCE_TYPE_MASS,
    SOURCE_TYPE_FLOWPACED,
    SOURCE_TYPE_SETPOINT,
)
from .s18_sources import (
    get_source_schema,
    get_source,
    set_source,
    add_source,
    delete_source,
)

from .s19_reactions import get_reaction_schema, get_reaction, set_reaction
from .s19_reactions import (
    get_pipe_reaction_schema,
    get_pipe_reaction,
    set_pipe_reaction,
)
from .s19_reactions import (
    get_tank_reaction_schema,
    get_tank_reaction,
    set_tank_reaction,
)

from .s20_mixing import (
    MIXING_MODEL_MIXED,
    MIXING_MODEL_2COMP,
    MIXING_MODEL_FIFO,
    MIXING_MODEL_LIFO,
)
from .s20_mixing import (
    get_mixing_schema,
    get_mixing,
    set_mixing,
    add_mixing,
    delete_mixing,
)

from .s21_times import (
    TIME_STATISTIC_NONE,
    TIME_STATISTIC_AVERAGED,
    TIME_STATISTIC_MINIMUM,
    TIME_STATISTIC_MAXIMUM,
    TIME_STATISTIC_RANGE,
)
from .s21_times import get_time_schema, get_time, set_time

from .s23_options_util import (
    OPTION_UNITS_CFS,
    OPTION_UNITS_GPM,
    OPTION_UNITS_MGD,
    OPTION_UNITS_IMGD,
    OPTION_UNITS_AFD,
    OPTION_UNITS_LPS,
    OPTION_UNITS_LPM,
    OPTION_UNITS_MLD,
    OPTION_UNITS_CMH,
    OPTION_UNITS_CMD,
)
from .s23_options_util import (
    OPTION_PRESSURE_PSI,
    OPTION_PRESSURE_KPA,
    OPTION_PRESSURE_METERS,
)
from .s23_options_util import OPTION_HEADLOSS_HW, OPTION_HEADLOSS_DW, OPTION_HEADLOSS_CM
from .s23_options_util import OPTION_UNBALANCED_STOP, OPTION_UNBALANCED_CONTINUE
from .s23_options_util import OPTION_DEMAND_MODEL_DDA, OPTION_DEMAND_MODEL_PDA
from .s23_options_util import (
    OPTION_QUALITY_NONE,
    OPTION_QUALITY_CHEMICAL,
    OPTION_QUALITY_AGE,
    OPTION_QUALITY_TRACE,
)
from .s23_options_util import get_option_schema, get_option
from .batch_api import set_option_ex

from .s23_options_util import (
    OPTION_V3_FLOW_UNITS_CFS,
    OPTION_V3_FLOW_UNITS_GPM,
    OPTION_V3_FLOW_UNITS_MGD,
    OPTION_V3_FLOW_UNITS_IMGD,
    OPTION_V3_FLOW_UNITS_AFD,
    OPTION_V3_FLOW_UNITS_LPS,
    OPTION_V3_FLOW_UNITS_LPM,
    OPTION_V3_FLOW_UNITS_MLD,
    OPTION_V3_FLOW_UNITS_CMH,
    OPTION_V3_FLOW_UNITS_CMD,
)
from .s23_options_util import (
    OPTION_V3_PRESSURE_UNITS_PSI,
    OPTION_V3_PRESSURE_UNITS_KPA,
    OPTION_V3_PRESSURE_UNITS_METERS,
)
from .s23_options_util import (
    OPTION_V3_HEADLOSS_MODEL_HW,
    OPTION_V3_HEADLOSS_MODEL_DW,
    OPTION_V3_HEADLOSS_MODEL_CM,
)
from .s23_options_util import (
    OPTION_V3_STEP_SIZING_FULL,
    OPTION_V3_STEP_SIZING_RELAXATION,
    OPTION_V3_STEP_SIZING_LINESEARCH,
)
from .s23_options_util import (
    OPTION_V3_IF_UNBALANCED_STOP,
    OPTION_V3_IF_UNBALANCED_CONTINUE,
)
from .s23_options_util import (
    OPTION_V3_DEMAND_MODEL_FIXED,
    OPTION_V3_DEMAND_MODEL_CONSTRAINED,
    OPTION_V3_DEMAND_MODEL_POWER,
    OPTION_V3_DEMAND_MODEL_LOGISTIC,
)
from .s23_options_util import (
    OPTION_V3_LEAKAGE_MODEL_NONE,
    OPTION_V3_LEAKAGE_MODEL_POWER,
    OPTION_V3_LEAKAGE_MODEL_FAVAD,
)
from .s23_options_util import (
    OPTION_V3_QUALITY_MODEL_NONE,
    OPTION_V3_QUALITY_MODEL_CHEMICAL,
    OPTION_V3_QUALITY_MODEL_AGE,
    OPTION_V3_QUALITY_MODEL_TRACE,
)
from .s23_options_util import (
    OPTION_V3_QUALITY_UNITS_HRS,
    OPTION_V3_QUALITY_UNITS_PCNT,
    OPTION_V3_QUALITY_UNITS_MGL,
    OPTION_V3_QUALITY_UNITS_UGL,
)
from .s23_options_util import get_option_v3_schema, get_option_v3
from .batch_api import set_option_v3_ex

from .s24_coordinates import get_node_coord, get_nodes_in_extent, get_links_in_extent

from .s25_vertices import (
    get_vertex_schema,
    get_vertex,
    set_vertex,
    add_vertex,
    delete_vertex,
)
from .s25_vertices import get_all_vertex_links, get_all_vertices

from .s26_labels import get_label_schema, get_label, set_label, add_label, delete_label

from .s27_backdrop import get_backdrop_schema, get_backdrop, set_backdrop

# -----------------------------------------------------------------------------
# SCADA 映射与遥测实体
# -----------------------------------------------------------------------------
from .s29_scada_device import (
    SCADA_DEVICE_TYPE_PRESSURE,
    SCADA_DEVICE_TYPE_DEMAND,
    SCADA_DEVICE_TYPE_QUALITY,
    SCADA_DEVICE_TYPE_LEVEL,
    SCADA_DEVICE_TYPE_FLOW,
    SCADA_DEVICE_TYPE_UNKNOWN,
)
from .s29_scada_device import (
    get_scada_device_schema,
    get_scada_device,
    set_scada_device,
    add_scada_device,
    delete_scada_device,
)
from .s29_scada_device import get_all_scada_device_ids, get_all_scada_devices
from .clean_api import clean_scada_device

from .s30_scada_device_data import (
    get_scada_device_data_schema,
    get_scada_device_data,
    set_scada_device_data,
    add_scada_device_data,
    delete_scada_device_data,
)
from .clean_api import clean_scada_device_data

from .s31_scada_element import (
    SCADA_MODEL_TYPE_JUNCTION,
    SCADA_MODEL_TYPE_RESERVOIR,
    SCADA_MODEL_TYPE_TANK,
    SCADA_MODEL_TYPE_PIPE,
    SCADA_MODEL_TYPE_PUMP,
    SCADA_MODEL_TYPE_VALVE,
)
from .s31_scada_element import SCADA_ELEMENT_STATUS_OFFLINE, SCADA_ELEMENT_STATUS_ONLINE
from .s31_scada_element import (
    get_scada_element_schema,
    get_scada_element,
    set_scada_element,
    add_scada_element,
    delete_scada_element,
)
from .s31_scada_element import get_all_scada_element_ids, get_all_scada_elements
from .clean_api import clean_scada_element

# -----------------------------------------------------------------------------
# 区域、DMA、服务分区、虚拟分区与需水分配
# -----------------------------------------------------------------------------
from .s32_region_util import (
    get_nodes_in_boundary,
    get_nodes_in_region,
    get_links_on_region_boundary,
    calculate_convex_hull,
    calculate_boundary,
    inflate_boundary,
    inflate_region,
)
from .s32_region import (
    get_region_schema,
    get_region,
    set_region,
    add_region,
    delete_region,
)

from .s33_dma_cal import PARTITION_TYPE_RB, PARTITION_TYPE_KWAY
from .s33_dma_cal import (
    calculate_district_metering_area_for_nodes,
    calculate_district_metering_area_for_region,
    calculate_district_metering_area_for_network,
)
from .s33_dma import (
    get_district_metering_area_schema,
    get_district_metering_area,
    set_district_metering_area,
    add_district_metering_area,
    delete_district_metering_area,
)
from .s33_dma import get_all_district_metering_area_ids, get_all_district_metering_areas
from .s33_dma_gen import (
    generate_district_metering_area,
    generate_sub_district_metering_area,
)

from .s34_sa_cal import calculate_service_area
from .s34_sa import (
    get_service_area_schema,
    get_service_area,
    set_service_area,
    add_service_area,
    delete_service_area,
)
from .s34_sa import get_all_service_area_ids, get_all_service_areas
from .s34_sa_gen import generate_service_area

from .s35_vd_cal import calculate_virtual_district
from .s35_vd import (
    get_virtual_district_schema,
    get_virtual_district,
    set_virtual_district,
    add_virtual_district,
    delete_virtual_district,
)
from .s35_vd import get_all_virtual_district_ids, get_all_virtual_districts
from .s35_vd_gen import generate_virtual_district

from .s36_wda_cal import (
    calculate_demand_to_nodes,
    calculate_demand_to_region,
    calculate_demand_to_network,
)

# -----------------------------------------------------------------------------
# 元数据与高级分析
# -----------------------------------------------------------------------------
from .s38_scada_info import get_scada_info_schema, get_scada_info, get_all_scada_info

from .s39_user import get_user_schema, get_user, get_all_users

from .s40_schema import get_scheme_schema, get_scheme, get_all_schemes

from .s41_pipe_risk_probability import (
    get_pipe_risk_probability_now,
    get_pipe_risk_probability,
    get_network_pipe_risk_probability_now,
    get_pipes_risk_probability,
    get_pipe_risk_probability_geometries,
)

from .s42_sensor_placement import get_all_sensor_placements

from .s43_burst_locate_result import get_all_burst_locate_results
