# Copyright (C) 2026 Wilhelmus Dingenus de Pooter
# SPDX-License-Identifier: GPL-3.0-or-later
"""
ENCore GIS — S-58 ENC validation subpackage.

Public API
==========
    run_validation(cell_paths, catalogue_dir, ...)   -> Report     (real cells)
    Validator, Report, Severity, Finding                            (engine)
    Catalogue                                                       (metadata)
    DictDataset, OgrDataset, Feature                                (model)

The core (engine + catalogue + attribute/structure checks) is pure stdlib.
Reading real cells (OgrDataset) and the spatial checks (GeomOps) require GDAL,
which QGIS provides; they are imported lazily so the package imports cleanly in
a plain Python environment for testing.

Targets IHO S-58 Edition 8.0.0 (October 2024). This release ships the engine
plus a first batch of checks; see COVERAGE.md for what is implemented vs TODO.
"""

from .engine import (Validator, Report, Severity, Finding, CheckMeta,
                     REGISTRY, load_all_checks)
from .catalogue import Catalogue
from .model import Dataset, DictDataset, NativeDataset, Feature
from .report_diff import diff_reports, ReportDiff

__all__ = [
    "Validator", "Report", "Severity", "Finding", "CheckMeta", "REGISTRY",
    "load_all_checks", "Catalogue", "Dataset", "DictDataset", "NativeDataset",
    "Feature", "run_validation", "diff_reports", "ReportDiff",
]

S58_EDITION = "8.0.0"


def run_validation(cell_paths, catalogue_dir, numbers=None, severities=None,
                   tolerance=1e-7, progress=None):
    """Validate one or more S-57 cells and return a Report.

    cell_paths      -- list of paths to .000 base cells (updates applied by GDAL)
    catalogue_dir   -- folder holding s57objectclasses.csv etc. (the plugin's
                       bundled s57catalogue/ directory)
    numbers/severities -- optional filters passed through to the runner
    tolerance       -- spatial tolerance (default 1/COMF = 1e-7 degrees)
    progress        -- optional callable(done, total, check_number)

    Requires GDAL (for reading cells and the spatial checks).
    """
    from .model import OgrDataset
    from .geometry import GeomOps

    load_all_checks()
    catalogue = Catalogue(catalogue_dir)
    dataset = OgrDataset(cell_paths)
    validator = Validator(catalogue, GeomOps(tolerance))
    return validator.run(dataset, numbers=numbers, severities=severities,
                         progress=progress)
