# -*- coding: utf-8 -*-
"""Duplicate geometry checker. Compares WKT strings."""
from .base import BaseChecker


class DuplicateChecker(BaseChecker):
    name = "duplicates"
    display_name_en = "Duplicates"
    display_name_vi = "Trung lap"

    def check(self, layer, params):
        seen, dupes, details = {}, [], []
        for feat in layer.getFeatures():
            g = feat.geometry()
            if not g or g.isNull():
                continue
            wkt = g.asWkt()
            if wkt in seen:
                dupes.append(g)
                details.append(f"Dup of FID {seen[wkt]}")
            else:
                seen[wkt] = feat.id()
        return {"error_geometries": dupes, "error_features": [], "details": details}

    def fix(self, input_path, output_path, params):
        """Pass through — duplicates are detected but never auto-deleted.

        Rationale: deleting features is destructive and irreversible.
        User should review duplicate locations and decide manually.
        """
        import shutil
        shutil.copy2(input_path, output_path)
        return output_path
