# -*- coding: utf-8 -*-
"""Algorithm registry — organized by geometry type.

Output of step N becomes input of step N+1.
Multipart MUST be first (changes feature count).
"""
from .multipart import MultipartChecker
from .invalid import InvalidChecker
from .unclosed import UnclosedChecker
from .duplicates import DuplicateChecker
from .overlaps import OverlapChecker
from .must_not_overlap import MustNotOverlapChecker
from .gaps import GapChecker
from .redundant import RedundantChecker
from .sliver import SliverChecker
from .missing_nodes import MissingNodeChecker
from .tiny_polygon import TinyPolygonChecker
from .line_checks import (
    LineDangleChecker, LineSelfIntersectionChecker,
    LineDuplicateChecker, LineOverlapChecker)
from .point_checks import (
    PointDuplicateChecker, PointInvalidCoordsChecker,
    PointIsolatedChecker)


# Mandatory fix order — do NOT rearrange
POLYGON_CHECKERS = [
    MultipartChecker,       # 1. Split multipart first
    InvalidChecker,         # 2. Fix invalid geometry
    UnclosedChecker,        # 3. Close rings
    DuplicateChecker,       # 4. Remove duplicates
    OverlapChecker,         # 5. Cut overlaps
    MustNotOverlapChecker,  # 6. Smart cut by area
    GapChecker,             # 7. Fill gaps
    RedundantChecker,       # 8. Reduce vertices
    SliverChecker,          # 9. Remove slivers
    MissingNodeChecker,     # 10. Insert missing nodes
    TinyPolygonChecker,     # 11. Merge tiny polygons
]

LINE_CHECKERS = [
    LineDangleChecker,              # 1. Dangling endpoints
    LineSelfIntersectionChecker,    # 2. Self-intersections
    LineDuplicateChecker,           # 3. Duplicate lines
    LineOverlapChecker,             # 4. Overlapping segments
]

POINT_CHECKERS = [
    PointDuplicateChecker,          # 1. Duplicate points
    PointInvalidCoordsChecker,      # 2. Invalid coordinates
    PointIsolatedChecker,           # 3. Isolated points
]

# Legacy compatibility
FIX_ORDER = POLYGON_CHECKERS

ALL_CHECKERS = {}
for cls_list in (POLYGON_CHECKERS, LINE_CHECKERS, POINT_CHECKERS):
    for cls in cls_list:
        ALL_CHECKERS[cls.name] = cls
