from __future__ import annotations

from enum import Enum
from typing import Dict
from typing import Optional
from typing import Tuple
from typing import TypedDict
from typing import Union


class OmegaMotor(str, Enum):
    diffrz = "diffrz"
    omega = "omega"


class Detector(str, Enum):
    frelon1 = "frelon1"
    frelon3 = "frelon3"
    eiger = "eiger"


class CorrectionFiles(TypedDict):
    bg_file: Optional[str]
    mask_file: Optional[str]
    dark_file: Optional[str]
    flat_file: Optional[str]


GAUSSIAN_SEGMENTER_DEFAULTS: Dict[str, Union[float, int]] = {
    "threshold": 70,
    "smooth_sigma": 1.0,
    "bgc": 0.9,
    "min_px": 3,
    "offset_threshold": 100,
    "ratio_threshold": 150,
}

LIMA_SEGMENTER_DEFAULTS: Dict[str, int] = {
    "lower_bound_cut": 2,
    "max_pixels_per_frame": 100000,
    "num_pixels_in_spot": 3,
}

MONITOR_KEYS: Tuple[str, str] = ("pico", "fpico")
CORRECTION_TOOLTIPS: Dict[str, str] = {
    "bg_file": """
        <b>Optional</b>: File containing detector background image.
        """,
    "mask_file": """
        <b>Optional</b>: File describing the detector mask.
        """,
    "flat_file": """
        <b>Optional</b>: File containing detector sensitivity image.
        """,
    "dark_file": """
        <b>Optional</b>: File containing detector offset image.
        """,
}

GAUSSIAN_SEGMENTER_TOOLTIPS: Dict[str, str] = {
    "threshold": """
        Minimum pixel intensity (in ADU) to be considered a potential peak.
        Used to eliminate low-signal noise.
        Typical range: 50-?
        """,
    "smooth_sigma": """
        Gaussian blur sigma value used for background smoothing.
        Higher values result in more smoothing.
        Typical range: 0.1-6.0
        """,
    "bgc": """
        Fractional background intensity value (in ADU).
        Fractional part of background per peak to remove.
        Typical range: 0.7-1.0
        """,
    "min_px": """
        Minimum number of connected pixels required to consider a region as a peak.
        Typical range: 1-?
        """,
    "offset_threshold": """
        Set intensity to a constant if it is less than this value.
        Typical range: 100-?
        Should satisfy: offset_threshold < ratio_threshold.
        """,
    "ratio_threshold": """
        Used to filter out peaks with an intensity higher than this value.
        Typical range: 150-?
        Should satisfy: offset_threshold < ratio_threshold.
        """,
}


LIMA_SEGMENTER_TOOLTIPS: Dict[str, str] = {
    "lower_bound_cut": """
        Pixel intensity threshold. Pixels with intensity lower than this value will be discarded.
        Typical values: 1 (low/no background) - 5 (high background like air scattering, quartz tube, etc.)
        """,
    "max_pixels_per_frame": """
        Limit the total number of pixels in a single frame.
        You normally don't need to modify this.
        """,
    "num_pixels_in_spot": """
        The minimum number of pixels a spot should have to survive the thresholding.
        Typical values: 3 (recommended) or more depending on background
        """,
}
