import json


import os.path

from vbv_lernwelt.learnpath.tests.competences_factories import CompetenceFactory, FullfilmentCriteriaFactory

competences_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'competences.json')


def create_default_competences(competences_json=competences_file):
    with open(competences_json) as f:
        competences_json = json.load(f)

    for index, compentence in enumerate(competences_json['competences']):

        competence_model = CompetenceFactory(name=compentence['name'], category_short=compentence['category_short'], sort_order=index)
        print(competence_model)

        for criteria_index, criteria in enumerate(compentence['fullfillment_criteria']):
            criteria_model = FullfilmentCriteriaFactory(name=criteria['name'], competence=competence_model, sort_order=criteria_index)
            print(criteria_model)

