# Path: lcopt/data_store.py
# class LcoptStorage():
#     def __init__(self):
#     def load_config(self):
#     def refresh(self):
#     def write_default_config(self):
#     def write_config(self, config):
#     def models(self):
#     def search_indices(self):
#     def project_type(self):
#     def single_project_name(self):
#     def ecoinvent_version(self):
#     def ecoinvent_system_model(self):
#     def save_option(self):
# 
# Path: lcopt/constants.py
# DEFAULT_PROJECT_STEM = "LCOPT_Setup_"
# 
# DEFAULT_BIOSPHERE_PROJECT = "LCOPT_Setup_biosphere"
# 
# DEFAULT_DB_NAME = DEFAULT_PROJECT_STEM[:-1]
# 
# FORWAST_PROJECT_NAME = DEFAULT_PROJECT_STEM + "Forwast"
# 
# FORWAST_URL = r"https://lca-net.com/wp-content/uploads/forwast.bw2package.zip"
# 
# ASSET_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'assets')
# 
# DEFAULT_CONFIG = {
#     'ecoinvent':{
#     	'username': None,
#     	'password': None,
#         'version': DEFAULT_ECOINVENT_VERSION,
#         'system_model': DEFAULT_ECOINVENT_SYSTEM_MODEL,
#     },
#     'model_storage': {
#         'location': DEFAULT_SAVE_OPTION,
#         'project': DEFAULT_PROJECT_TYPE,
#         },
#     }
# 
# DEFAULT_SINGLE_PROJECT = "LCOPT_Models"


import tempfile
import requests
import zipfile
import io
import os
import eidl
import yaml
import pickle
import getpass
import socket
    import brightway2 as bw2
from functools import partial
from .data_store import storage
from .constants import (DEFAULT_PROJECT_STEM,
                        DEFAULT_BIOSPHERE_PROJECT,
                        DEFAULT_DB_NAME,
                        FORWAST_PROJECT_NAME,
                        FORWAST_URL,
                        ASSET_PATH,
                        DEFAULT_CONFIG,
                        DEFAULT_SINGLE_PROJECT)
    default_ei_name = "Ecoinvent3_3_cutoff"

    if db_name is None:
        
        db_name = DEFAULT_PROJECT_STEM + default_ei_name

    if db_name in bw2.projects:
        if overwrite:                                           
            bw2.projects.delete_project(name=db_name, delete_dir=True)
        else:
            print('Looks like bw2 is already set up - if you want to overwrite the existing version run lcopt.utils.lcopt_bw2_setup in a python shell using overwrite = True')
            return False

    bw2.projects.set_current(db_name)
    bw2.bw2setup()
    ei = bw2.SingleOutputEcospold2Importer(fix_mac_path_escapes(ecospold_path), default_ei_name)
    ei.apply_strategies()
    ei.statistics()
    ei.write_database()

    return True

def bw2_project_exists(project_name):
    return project_name in bw2.projects

def upgrade_old_default():

    default_ei_name = "Ecoinvent3_3_cutoff"
    bw2.projects.set_current(DEFAULT_PROJECT_STEM[:-1])
    bw2.projects.copy_project(DEFAULT_PROJECT_STEM + default_ei_name, switch=True)

# Path: lcopt/data_store.py
# class LcoptStorage():
#     def __init__(self):
#     def load_config(self):
#     def refresh(self):
#     def write_default_config(self):
#     def write_config(self, config):
#     def models(self):
#     def search_indices(self):
#     def project_type(self):
#     def single_project_name(self):
#     def ecoinvent_version(self):
#     def ecoinvent_system_model(self):
#     def save_option(self):
# 
# Path: lcopt/constants.py
# DEFAULT_PROJECT_STEM = "LCOPT_Setup_"
# 
# DEFAULT_BIOSPHERE_PROJECT = "LCOPT_Setup_biosphere"
# 
# DEFAULT_DB_NAME = DEFAULT_PROJECT_STEM[:-1]
# 
# FORWAST_PROJECT_NAME = DEFAULT_PROJECT_STEM + "Forwast"
# 
# FORWAST_URL = r"https://lca-net.com/wp-content/uploads/forwast.bw2package.zip"
# 
# ASSET_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'assets')
# 
# DEFAULT_CONFIG = {
#     'ecoinvent':{
#     	'username': None,
#     	'password': None,
#         'version': DEFAULT_ECOINVENT_VERSION,
#         'system_model': DEFAULT_ECOINVENT_SYSTEM_MODEL,
#     },
#     'model_storage': {
#         'location': DEFAULT_SAVE_OPTION,
#         'project': DEFAULT_PROJECT_TYPE,
#         },
#     }
# 
# DEFAULT_SINGLE_PROJECT = "LCOPT_Models"


# Path: lcopt/utils.py
import tempfile
import requests
import zipfile
import io
import os
import eidl
import yaml
import pickle
import getpass
import socket
    import brightway2 as bw2
from functools import partial
from .data_store import storage
from .constants import (DEFAULT_PROJECT_STEM,
                        DEFAULT_BIOSPHERE_PROJECT,
                        DEFAULT_DB_NAME,
                        FORWAST_PROJECT_NAME,
                        FORWAST_URL,
                        ASSET_PATH,
                        DEFAULT_CONFIG,
                        DEFAULT_SINGLE_PROJECT)

    default_ei_name = "Ecoinvent3_3_cutoff"

    if db_name is None:
        
        db_name = DEFAULT_PROJECT_STEM + default_ei_name

    if db_name in bw2.projects:
        if overwrite:                                           
            bw2.projects.delete_project(name=db_name, delete_dir=True)
        else:
            print('Looks like bw2 is already set up - if you want to overwrite the existing version run lcopt.utils.lcopt_bw2_setup in a python shell using overwrite = True')
            return False

    bw2.projects.set_current(db_name)
    bw2.bw2setup()
    ei = bw2.SingleOutputEcospold2Importer(fix_mac_path_escapes(ecospold_path), default_ei_name)
    ei.apply_strategies()
    ei.statistics()
    ei.write_database()

    return True

def bw2_project_exists(project_name):
    return project_name in bw2.projects

def upgrade_old_default():

    default_ei_name = "Ecoinvent3_3_cutoff"
    bw2.projects.set_current(DEFAULT_PROJECT_STEM[:-1])
    bw2.projects.copy_project(DEFAULT_PROJECT_STEM + default_ei_name, switch=True)

    write_search_index(DEFAULT_PROJECT_STEM + default_ei_name, default_ei_name)