from django.conf import settings

TEACHER_KEY = "teacher"
STUDENT_KEY = "student"
MYSKILLBOX_PLATFORM = "myskillbox"
MYKV_PLATFORM = "my-kv"
MYDHA_PLATFORM = "my-dha"
MYDHF_PLATFORM = "my-dhf"

MYSKILLBOX_LICENSES = {
    "978-3-0355-1397-4": {
        "edition": STUDENT_KEY,
        "duration": 4 * 365,
        "name": "Student 4 years",
        "platform": MYSKILLBOX_PLATFORM,
        "default": True,
    },
    "978-3-0355-1860-3": {
        "edition": STUDENT_KEY,
        "duration": 365,
        "name": "Student 1 year",
        "platform": MYSKILLBOX_PLATFORM,
    },
    "978-3-0355-1862-7": {
        "edition": STUDENT_KEY,
        "duration": 30,
        "name": "Student test 1 month",
        "platform": MYSKILLBOX_PLATFORM,
    },
    "978-3-0355-1861-0": {
        "edition": TEACHER_KEY,
        "duration": 30,
        "name": "Teacher test 1 month",
        "platform": MYSKILLBOX_PLATFORM,
    },
    "978-3-0355-1823-8": {
        "edition": TEACHER_KEY,
        "duration": 365,
        "name": "Teacher 1 year",
        "platform": MYSKILLBOX_PLATFORM,
    },
}

MYKV_LICENSES = {
    "978-3-0355-2359-1": {
        "edition": STUDENT_KEY,
        "duration": 4 * 365,
        "name": "myKV Lizenz für Lernende, gültig 4 Jahre",
        "platform": MYKV_PLATFORM,
        "default": True,
    },
    "978-3-0355-2360-7": {
        "edition": STUDENT_KEY,
        "duration": 2 * 365,
        "name": "myKV Lizenz für Lernende, gültig 4 Jahre",
        "platform": MYKV_PLATFORM,
    },
    "978-3-0355-2361-4": {
        "edition": TEACHER_KEY,
        "duration": 1 * 365,
        "name": "myKV-Lizenzen für Lehrpersonen, gültig für 1 Jahr",
        "platform": MYKV_PLATFORM,
    },
    "978-3-0355-2189-4": {
        "edition": STUDENT_KEY,
        "duration": 30,
        "name": "Student 1 Monat Testlizenz",
        "platform": MYKV_PLATFORM,
    },
    "978-3-0355-2188-7": {
        "edition": TEACHER_KEY,
        "duration": 30,
        "name": "Lehrperson 1 Monat Testlizenz",
        "platform": MYKV_PLATFORM,
    },
}

MYDHA_LICENSES = {
    "978-3-0355-2371-3": {
        "edition": STUDENT_KEY,
        "duration": 4 * 365,
        "name": "myDHA Lizenz für Lernende, gültig 4 Jahre",
        "platform": MYDHA_PLATFORM,
        "default": True,
    },
    "978-3-0355-2372-0": {
        "edition": TEACHER_KEY,
        "duration": 1 * 365,
        "name": "myDHA Lizenzen für Lehrpersonen, gültig für 1 Jahr",
        "platform": MYDHA_PLATFORM,
    },
    "978-3-0355-2276-1": {
        "edition": TEACHER_KEY,
        "duration": 30,
        "name": "myDetailhandel DHA - Lehrpersonen (Testlizenz)",
        "platform": MYDHA_PLATFORM,
    },
    "978-3-0355-2275-4": {
        "edition": STUDENT_KEY,
        "duration": 30,
        "name": "myDetailhandel DHA - Lernende (Testlizenz)",
        "platform": MYDHA_PLATFORM,
    },
}

MYDHF_LICENSES = {
    "978-3-0355-2369-0": {
        "edition": STUDENT_KEY,
        "duration": 4 * 365,
        "name": "myDHF Lizenz für Lernende, gültig 4 Jahre",
        "platform": MYDHF_PLATFORM,
        "default": True,
    },
    "978-3-0355-2370-6": {
        "edition": TEACHER_KEY,
        "duration": 1 * 365,
        "name": "myDHF Lizenzen für Lehrpersonen, gültig für 1 Jahr",
        "platform": MYDHF_PLATFORM,
    },
    "978-3-0355-2274-7": {
        "edition": TEACHER_KEY,
        "duration": 30,
        "name": "myDetailhandel DHF - Lehrpersonen (Testlizenz)",
        "platform": MYDHF_PLATFORM,
    },
    "978-3-0355-2273-0": {
        "edition": STUDENT_KEY,
        "duration": 30,
        "name": "myDetailhandel DHF - Lernende (Testlizenz)",
        "platform": MYDHF_PLATFORM,
    },
}

LICENSES = dict(
    **MYSKILLBOX_LICENSES, **MYKV_LICENSES, **MYDHA_LICENSES, **MYDHF_LICENSES
)


def get_license_dict():
    return {k: v for k, v in LICENSES.items() if v.get("platform") == settings.PLATFORM}


def get_valid_isbns():
    return list(get_license_dict().keys())


def is_myskillbox_product(isbn):
    return isbn in get_valid_isbns()


def get_default_isbn():
    defaults = {k: v for k, v in get_license_dict().items() if v.get("default", False)}
    default_isbns = list(defaults.keys())
    return default_isbns[0]
