"""DCML annotation standard codec registrations.

Import this module to activate the DCML codec::

    import flexohr.codecs.dcml
"""

from __future__ import annotations

from flexohr.harmony.harmony_enums import (
    ChordQuality,
    Inversion,
)

# ── ChordQuality DCML codec ──

ChordQuality.register_standard(
    "dcml",
    {
        "major_triad": "M",
        "minor_triad": "m",
        "diminished_triad": "o",
        "augmented_triad": "+",
        "dominant_seventh": "Mm7",
        "minor_seventh": "mm7",
        "major_seventh": "MM7",
        "minor_major_seventh": "mM7",
        "diminished_seventh": "o7",
        "half_diminished_seventh": "%7",
        "augmented_seventh": "+7",
        "augmented_major_seventh": "+M7",
        "italian_sixth": "It",
        "german_sixth": "Ger",
        "french_sixth": "Fr",
    },
)

# ── Inversion DCML codec (figbass strings) ──
# Each DCML figbass string uniquely identifies an inversion:
#   Triads:  "" → root, "6" → first, "64" → second
#   Sevenths: "7" → root, "65" → first, "43" → second, "2" → third

Inversion.register_standard(
    "dcml",
    {
        "root_position": "",
        "first": "6",
        "second": "64",
        # Note: "7", "65", "43", "2" are seventh-chord figbass synonyms
        # for the same inversions.  We register the triad forms as canonical
        # and add the seventh forms below.
        # ToDo: refactor to define mappings in the other direction, always
    },
)

# Register seventh-chord figbass as additional decodings.
# These map *from* the DCML string *to* the enum member, but the canonical
# encoding (enum → string) uses the triad forms above.
_inv_reg = Inversion._codec_registry
if "dcml" in _inv_reg._decoders:
    _inv_reg._decoders["dcml"]["7"] = "root_position"
    _inv_reg._decoders["dcml"]["65"] = "first"
    _inv_reg._decoders["dcml"]["43"] = "second"
    _inv_reg._decoders["dcml"]["2"] = "third"
