from pathlib import Path
import json


def get_model_path(model_name, model_type=None):
    """
    creates the path based on the model_name
    
    model_name: string value indicationg the <org>/<model>/<version>
    model_type: model type for braingen and kwyk model

    Returns
    -------
    model_path: path to pretrained model file in trained_models repository
    
    """
    database_path = Path(__file__).resolve().parent / "model_database.json"
    with open(database_path, "r") as fp:
        models=json.load(fp)
    
    org,mdl,ver = model_name.split("/")
        
    root_path = Path(__file__).resolve().parent / "trained-models"
    
    if not model_type:
        return root_path / model_name / models[model_name]
    else:
        return root_path / model_name / models[model_name][model_type]