53 lines
2.6 KiB
TypeScript
53 lines
2.6 KiB
TypeScript
"use client";
|
||
|
||
import { useQuery } from "@tanstack/react-query";
|
||
|
||
import { apiFetch } from "@/lib/api";
|
||
import type { components } from "@/lib/api-types";
|
||
|
||
// Reuse generated OpenAPI types (api-types.ts) — НЕ дублировать руками.
|
||
export type ConnectionCapacityResponse =
|
||
components["schemas"]["ConnectionCapacityResponse"];
|
||
export type PowerConnectionPoint =
|
||
components["schemas"]["PowerConnectionPoint"];
|
||
export type PowerCapacitySummary =
|
||
components["schemas"]["PowerCapacitySummary"];
|
||
export type WaterCapacityRow = components["schemas"]["WaterCapacityRow"];
|
||
export type GasCapacityBlock = components["schemas"]["GasCapacityBlock"];
|
||
export type GasGrsRow = components["schemas"]["GasGrsRow"];
|
||
export type GasOutletPoint = components["schemas"]["GasOutletPoint"];
|
||
export type HeatCapacityBlock = components["schemas"]["HeatCapacityBlock"];
|
||
export type HeatSystemRow = components["schemas"]["HeatSystemRow"];
|
||
export type NearbyNetworkZone = components["schemas"]["NearbyNetworkZone"];
|
||
|
||
/**
|
||
* Радиус поиска центров питания (ЦП, ПС 35/110 кВ) вокруг участка. Дефолт 3 км —
|
||
* согласован с бэкендом (GET /connection-capacity?radius_m=…). Держим отдельной
|
||
* константой, чтобы подпись «в радиусе N км» и запрос не расходились.
|
||
*/
|
||
export const CONNECTION_CAPACITY_RADIUS_M = 3000;
|
||
|
||
/**
|
||
* Ресурсные резервы для ТП (#connection-capacity): ближайшие центры питания
|
||
* Россетей со свободной мощностью (power_points/power_summary) + резервы ЦСВ/ЦСК
|
||
* Водоканала (water). Источник — обязательное раскрытие сетевых организаций.
|
||
*
|
||
* Зеркалит useUtilityInfrastructure/useConnectionPoints: apiFetch, queryKey-массив,
|
||
* staleTime 5 мин, enabled по cadNum. Сервер — единственный источник истины по
|
||
* форме ответа (см. ConnectionCapacityResponse в api-types.ts).
|
||
*/
|
||
export function useConnectionCapacity(
|
||
cadNum: string | null | undefined,
|
||
radiusM: number = CONNECTION_CAPACITY_RADIUS_M,
|
||
enabled = true,
|
||
) {
|
||
return useQuery<ConnectionCapacityResponse>({
|
||
queryKey: ["connection-capacity", cadNum, radiusM],
|
||
queryFn: () =>
|
||
apiFetch<ConnectionCapacityResponse>(
|
||
`/api/v1/parcels/${encodeURIComponent(cadNum!)}/connection-capacity?radius_m=${radiusM}`,
|
||
),
|
||
enabled: !!cadNum && enabled,
|
||
staleTime: 5 * 60 * 1000,
|
||
});
|
||
}
|