from pathlib import Path
import configparser


def create_config(location:Path, db_path:Path, folders:dict) -> Path:
    """
    Create a new default configuration file with the paths set to the
    default paths.

    ##### Parameters
    location : Path
        Location of data intake project

    db_path : Path
        Location of the data intake database

    folders : dict
        Dictionary with the folder paths for 'delivery', 'raw', and 'datasets'
    """
    if location is None:
        location = Path.cwd()

    cfg = configparser.ConfigParser()
    d = dict()
    d['root_data'] = location
    d['delivery_folder'] = folders['delivery']
    d['raw_data_folder'] = folders['raw']
    d['datasets_folder'] = folders['datasets']
    d['data_intake_db'] = db_path


    cfg['PATHS'] = d

    d = dict()
    d['force_recalculate'] = False
    cfg['FLAGS'] = d

    d = dict()
    d['data_extensions'] = '\n'.join(["data", "parquet", "hdf5"])
    d['report_extensions'] = '\n'.join(['report','md','html','pptx','docx'])
    d['script_extensions'] = '\n'.join(['script', 'ipynb', 'py', 'r', 'jl', 'sh'])
    cfg['EXTENSIONS'] = d

    if not (location / '.config' / 'config.ini').is_file():
        with open((location / '.config' / 'config.ini'), mode='w') as f:
            cfg.write(f)
    else:
        print('[!] config.ini already exists, using existing version')

    return (location / '.config' / 'config.ini')