import * as circuit_json from 'circuit-json';
import { AnyCircuitElement, PcbPortNotConnectedError, PcbTraceError, PcbPlacementError, PcbComponentOutsideBoardError, PcbViaClearanceError, PcbTraceWarning, PcbTraceMissingError, PcbFootprintOverlapError, PcbTraceTooLongWarning, PcbPadPadClearanceError, PcbPadTraceClearanceError, PcbViaTraceClearanceError, SourceComponentPinsUnderspecifiedWarning, SourceNoPowerPinDefinedWarning, SourceNoGroundPinDefinedWarning, PcbConnectorNotInAccessibleOrientationWarning } from 'circuit-json';
import { ConnectivityMap } from 'circuit-json-to-connectivity-map';

declare function checkEachPcbPortConnectedToPcbTraces(circuitJson: AnyCircuitElement[]): PcbPortNotConnectedError[];

declare function checkEachPcbTraceNonOverlapping(circuitJson: AnyCircuitElement[], { connMap, minClearance, }?: {
    connMap?: ConnectivityMap;
    minClearance?: number;
}): PcbTraceError[];

declare class NetManager {
    private networks;
    setConnected(nodes: string[]): void;
    isConnected(nodes: string[]): boolean;
}

declare function checkViasOffBoard(circuitJson: AnyCircuitElement[]): PcbPlacementError[];

/**
 * Main function — polygon-first: construct polygons, test containment / intersection,
 * compute overlap distance using boolean intersection area or geometric distance.
 */
declare function checkPcbComponentsOutOfBoard(circuitJson: AnyCircuitElement[]): PcbComponentOutsideBoardError[];

declare function checkSameNetViaSpacing(circuitJson: AnyCircuitElement[], { connMap, minClearance, }?: {
    connMap?: ConnectivityMap;
    minClearance?: number;
}): PcbViaClearanceError[];

declare function checkDifferentNetViaSpacing(circuitJson: AnyCircuitElement[], { connMap, minClearance, }?: {
    connMap?: ConnectivityMap;
    minClearance?: number;
}): PcbViaClearanceError[];

declare function checkSourceTracesMatchPcbTraceThickness(circuitJson: AnyCircuitElement[]): PcbTraceWarning[];

/**
 * Check that each source_trace which connects source ports has at least one
 * pcb_trace associated with it. If a source_trace has no corresponding
 * pcb_trace, return an error for that source_trace.
 */
declare function checkSourceTracesHavePcbTraces(circuitJson: AnyCircuitElement[]): PcbTraceMissingError[];

declare function checkTracesAreContiguous(circuitJson: AnyCircuitElement[]): PcbTraceError[];

/**
 * Configuration for trace board boundary checking
 */
interface TraceBoardCheckConfig {
    /** Minimum distance from trace center to board edge (in mm) */
    margin?: number;
}
/**
 * Check if any trace segment is too close to or outside the board outline
 * Uses segment-to-polygon distance with configurable margin
 */
declare function checkPcbTracesOutOfBoard(circuitJson: AnyCircuitElement[], config?: TraceBoardCheckConfig): PcbTraceError[];

/**
 * Check for overlapping PCB components
 * Returns errors for components that overlap inappropriately
 */
declare function checkPcbComponentOverlap(circuitJson: AnyCircuitElement[]): PcbFootprintOverlapError[];

declare const checkPcbTraceLengths: (circuitJson: AnyCircuitElement[]) => PcbTraceTooLongWarning[];

declare function checkPadPadClearance(circuitJson: AnyCircuitElement[], { connMap, minClearance, }?: {
    connMap?: ConnectivityMap;
    minClearance?: number;
}): PcbPadPadClearanceError[];

declare function checkPadTraceClearance(circuitJson: AnyCircuitElement[], { connMap, minClearance, }?: {
    connMap?: ConnectivityMap;
    minClearance?: number;
}): PcbPadTraceClearanceError[];

declare function checkViaTraceClearance(circuitJson: AnyCircuitElement[], { connMap, minClearance, }?: {
    connMap?: ConnectivityMap;
    minClearance?: number;
}): PcbViaTraceClearanceError[];

declare function checkViaPadClearance(circuitJson: AnyCircuitElement[], { connMap, minClearance, }?: {
    connMap?: ConnectivityMap;
    minClearance?: number;
}): PcbPadPadClearanceError[];

declare function checkViasInPads(circuitJson: AnyCircuitElement[]): PcbPlacementError[];

/**
 * Removes generic pcb_trace_error records when a more specific pad-trace or
 * via-trace clearance error describes the same physical pair.
 *
 * The specific record is retained because it includes the measured and
 * required clearance. Trace-trace and all other generic errors are untouched.
 *
 * @deprecated Aggregate runners now classify trace-obstacle pairs as either
 * overlap or clearance before combining results, so they no longer need this
 * post-processing step. Kept for callers combining results from older checks.
 */
declare const dedupePcbDrcErrors: <T extends AnyCircuitElement>(errors: T[]) => T[];

type SourcePinMustBeConnectedError = {
    type: "source_pin_must_be_connected_error";
    source_pin_must_be_connected_error_id: string;
    error_type: "source_pin_must_be_connected_error";
    message: string;
    source_component_id: string;
    source_port_id: string;
    subcircuit_id?: string;
};
/**
 * Check that each source port with must_be_connected attribute is actually
 * connected to a trace. Returns errors for any pins that are marked as
 * must_be_connected but are floating (not connected to any trace).
 */
declare function checkPinMustBeConnected(circuitJson: AnyCircuitElement[]): SourcePinMustBeConnectedError[];

/**
 * Check that each component with ports has at least one pin attribute
 * specified across its ports. Returns a warning when all pins are
 * underspecified (no SourcePinAttributes fields set on any port).
 */
declare function checkAllPinsInComponentAreUnderspecified(circuitJson: AnyCircuitElement[]): SourceComponentPinsUnderspecifiedWarning[];

/**
 * Check that each chip has at least one pin marked as requires_power=true.
 * Returns warnings for chips where no pin declares requires_power.
 */
declare function checkNoPowerPinDefined(circuitJson: AnyCircuitElement[]): SourceNoPowerPinDefinedWarning[];

/**
 * Check that each chip has at least one pin marked as requires_ground=true.
 * Returns warnings for chips where no pin declares requires_ground.
 */
declare function checkNoGroundPinDefined(circuitJson: AnyCircuitElement[]): SourceNoGroundPinDefinedWarning[];

declare function runAllPlacementChecks(circuitJson: AnyCircuitElement[]): Promise<(circuit_json.PcbPlacementError | circuit_json.PcbComponentOutsideBoardError | circuit_json.PcbFootprintOverlapError | circuit_json.PcbPadPadClearanceError | circuit_json.PcbConnectorNotInAccessibleOrientationWarning | circuit_json.PcbCourtyardOverlapError)[]>;
declare function runAllNetlistChecks(circuitJson: AnyCircuitElement[]): Promise<{
    type: "source_pin_must_be_connected_error";
    source_pin_must_be_connected_error_id: string;
    error_type: "source_pin_must_be_connected_error";
    message: string;
    source_component_id: string;
    source_port_id: string;
    subcircuit_id?: string;
}[]>;
declare function runAllPinSpecificationChecks(circuitJson: AnyCircuitElement[]): Promise<(circuit_json.SourceComponentPinsUnderspecifiedWarning | circuit_json.SourceNoPowerPinDefinedWarning | circuit_json.SourceNoGroundPinDefinedWarning)[]>;
declare function runAllRoutingChecks(circuitJson: AnyCircuitElement[]): Promise<(circuit_json.PcbPortNotConnectedError | circuit_json.PcbTraceError | circuit_json.PcbViaClearanceError | circuit_json.PcbTraceMissingError | circuit_json.PcbTraceTooLongWarning | circuit_json.PcbPadPadClearanceError | circuit_json.PcbPadTraceClearanceError | circuit_json.PcbViaTraceClearanceError)[]>;
declare function runAllChecks(circuitJson: AnyCircuitElement[]): Promise<(circuit_json.PcbPortNotConnectedError | circuit_json.PcbTraceError | circuit_json.PcbPlacementError | circuit_json.PcbComponentOutsideBoardError | circuit_json.PcbViaClearanceError | circuit_json.PcbTraceMissingError | circuit_json.PcbFootprintOverlapError | circuit_json.PcbTraceTooLongWarning | circuit_json.PcbPadPadClearanceError | circuit_json.PcbPadTraceClearanceError | circuit_json.PcbViaTraceClearanceError | {
    type: "source_pin_must_be_connected_error";
    source_pin_must_be_connected_error_id: string;
    error_type: "source_pin_must_be_connected_error";
    message: string;
    source_component_id: string;
    source_port_id: string;
    subcircuit_id?: string;
} | circuit_json.SourceComponentPinsUnderspecifiedWarning | circuit_json.SourceNoPowerPinDefinedWarning | circuit_json.SourceNoGroundPinDefinedWarning | circuit_json.PcbConnectorNotInAccessibleOrientationWarning | circuit_json.PcbCourtyardOverlapError)[]>;

declare function checkConnectorAccessibleOrientation(circuitJson: AnyCircuitElement[]): PcbConnectorNotInAccessibleOrientationWarning[];

/**
 * Test points are intended to be contacted from their PCB side. A test point
 * whose access center is covered by another component's courtyard cannot be
 * reliably reached by a probe after assembly.
 */
declare function checkTestPointAccessibility(circuitJson: AnyCircuitElement[]): PcbPlacementError[];

export { NetManager, checkAllPinsInComponentAreUnderspecified, checkConnectorAccessibleOrientation, checkDifferentNetViaSpacing, checkEachPcbPortConnectedToPcbTraces, checkEachPcbTraceNonOverlapping, checkNoGroundPinDefined, checkNoPowerPinDefined, checkPadPadClearance, checkPadTraceClearance, checkPcbComponentOverlap, checkPcbComponentsOutOfBoard, checkPcbTraceLengths, checkPcbTracesOutOfBoard, checkPinMustBeConnected, checkSameNetViaSpacing, checkSourceTracesHavePcbTraces, checkSourceTracesMatchPcbTraceThickness, checkTestPointAccessibility, checkTracesAreContiguous, checkViaPadClearance, checkViaTraceClearance, checkViasInPads, checkViasOffBoard, dedupePcbDrcErrors, runAllChecks, runAllNetlistChecks, runAllPinSpecificationChecks, runAllPlacementChecks, runAllRoutingChecks };
