from aqt import mw

from .config import get, set


def prepare_deck_to_ease_range():

    deck_to_ease_range = d if (d := get('deck_to_ease_range')) else {}

    # for backwards compatibilty
    deck_to_ease = d if (d := get('deck_to_ease')) else {}
    deck_to_ease_range.update(**_to_deck_to_ease_range(deck_to_ease))
    set('deck_to_ease', None)

    # remove entries of decks that do not exist in anki
    # and ensure the deck ids are of type int
    cleaned = {
        int(deck_id) : ease_range
        for deck_id, ease_range in deck_to_ease_range.items()
        if str(deck_id) in mw.col.decks.allIds()
    }
    set('deck_to_ease_range', cleaned)

def _to_deck_to_ease_range(deck_to_ease):
    converted = {
        deck_id : (ease, ease)
        for deck_id, ease in deck_to_ease.items()
    }
    return converted
    
from aqt import mw

from .config import get, set


def prepare_deck_to_ease_range():

    deck_to_ease_range = d if (d := get('deck_to_ease_range')) else {}

    # for backwards compatibilty
    deck_to_ease = d if (d := get('deck_to_ease')) else {}
    deck_to_ease_range.update(**_to_deck_to_ease_range(deck_to_ease))
    set('deck_to_ease', None)

    # remove entries of decks that do not exist in anki
    # and ensure the deck ids are of type int
    cleaned = {
        int(deck_id) : ease_range
        for deck_id, ease_range in deck_to_ease_range.items()
        if str(deck_id) in mw.col.decks.allIds()
    }
    set('deck_to_ease_range', cleaned)

def _to_deck_to_ease_range(deck_to_ease):
    converted = {
        deck_id : (ease, ease)
        for deck_id, ease in deck_to_ease.items()
    }
    return converted
    
# for backwards compatibilty # remove entries of decks that do not exist in anki # and ensure the deck ids are of type int