from django.conf import settings

TEACHER_KEY = 'teacher'
STUDENT_KEY = 'student'
MYSKILLBOX_PLATFORM = 'myskillbox'
MYKV_PLATFORM = 'my-kv'
DHA_PLATFORM = 'my-dha'
DHF_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
    },
    '978-3-0355-2189-4': {
        'edition': STUDENT_KEY,
        'duration': 400,
        'name': 'Student test 1 month',
        'platform': MYKV_PLATFORM,
        'default': True
    },
    '978-3-0355-2188-7': {
        'edition': TEACHER_KEY,
        'duration': 400,
        'name': 'Student test 1 month',
        'platform': MYKV_PLATFORM
    },
    '978-3-0355-2276-1': {
        'edition': TEACHER_KEY,
        'duration': 260,
        'name': 'myDetailhandel DHA - Lehrpersonen (Lizenz)',
        'platform': DHA_PLATFORM
    },
    '978-3-0355-2275-4': {
        'edition': STUDENT_KEY,
        'duration': 260,
        'name': 'myDetailhandel DHA - Lernende (Lizenz)',
        'platform': DHA_PLATFORM
    },
    '978-3-0355-2274-7': {
        'edition': TEACHER_KEY,
        'duration': 260,
        'name': 'myDetailhandel DHF - Lehrpersonen (Lizenz)',
        'platform': DHF_PLATFORM
    },
    '978-3-0355-2273-0': {
        'edition': STUDENT_KEY,
        'duration': 260,
        'name': 'myDetailhandel DHF - Lernende (Lizenz)',
        'platform': DHF_PLATFORM
    },
}


def get_license_dict():
    return {
        k: v for k, v in MYSKILLBOX_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]
