from __future__ import annotations

from enum import Enum
from typing import Dict


class Symmetry(str, Enum):
    cubic = "cubic"
    hexagonal = "hexagonal"
    trigonal = "trigonal"
    rhombohedralP = "rhombohedralP"
    trigonalP = "trigonalP"
    tetragonal = "tetragonal"
    orthorhombic = "orthorhombic"
    monoclinic_c = "monoclinic_c"
    monoclinic_a = "monoclinic_a"
    monoclinic_b = "monoclinic_b"
    triclinic = "triclinic"


LOG_INACTIVITY_TIMEOUT_SEC: int = 30
MONITOR_INTERVAL_M_SEC: int = 10000
PLOT_GRAIN_UPDATE_TIME_SEC = 3.0
PLOT_GRAIN_UPDATE_TIME_M_SEC = 3000
FAST_THREAD_TIMEOUT_SEC = 0.1


INDEXER_TOOLTIPS: Dict[str, str] = {
    "nbPeaks": """
        Minimum number of peaks needed to index a grain.
        Set this to ensure only grains with a sensible number of peaks are kept. A reliable starting value is:
        180° Rotation: 65-80% of the total expected peaks for Ring 1.
        360° Rotation: 130-160% of the total expected peaks for Ring 1.
        If this number is too low, you will index grains that might be fake (some peaks will always "accidentally" work with a grain).
        If this number is too high, you will incorrectly discard real grains.
        In general, after indexing and refining, all your grains should have a similar number of peaks.
        """,
    "ring1": """
        "Ring 1 indices as comma-separated integers. Must be a subset of the ring indices picked in indexing filtering."
        """,
    "ring2": """
        Ring 2 indices as comma-separated integers. Must be a subset of the ring indices picked in indexing filtering.
        """,
    "tolangle": """
        Tolerance angle in degrees.
        During grid indexing, we can find the same grain many times at neighbouring grid points (indexing in parallel).
        We handle this via a grain de-duplication step, that checks to see if we already found each grain before.
        We de-duplicate based on centre-of-mass distance and (symmetry-aware) misorientation angle
        tolangle and toldist control the de-duplication tolerances.
        Typical values: 0.1 - 2.0, depending on how textured your sample is.
        """,
    "toldist": """
        Tolerance Distance, usually in range of 0.5 to 2 times detector pixel width.
        See Tolerance Angle for more information
        """,
    "dstol": """
        Distance in reciprocal space to consider a peak as being on/off a HKL ring.
        Typical values: 1e-4 to 1e-3
        This value can be quite small, because we correct for the grain centre-of-mass position in the grid indexing before assigning to rings.
        """,
    "genrings": """
        Indices of rings used for generating UBI. At least two are needed but are enough in most cases.
        """,
    "scorerings": """
        Indices of the rings used for scoring. These must contain the indices used for indexing.
        """,
    "wavelength": """
        wavelength used in the geometry transformation task
        """,
    "maxGrains": """
        Limits the number of found grains.
        """,
}
