# Path: distance/_nonlevel.py
# class WorkshopLevelInfos(BaseObject):
# 
#     type = 'WorkshopLevelInfos'
# 
# Path: distance_scripts/_common.py
# def get_cache_filename(filename):
#     return os.path.join(CACHE_PATH, filename)
# 
# def get_profile_filename(filename):
#     return os.path.join(PROFILE_PATH, filename)


import argparse
import sqlite3
from distance import WorkshopLevelInfos
from ._common import get_cache_filename, get_profile_filename



def main():
    parser = argparse.ArgumentParser(
        description=__doc__)
    parser.add_argument("--db", help="database filename.")
    parser.add_argument("FILE", nargs='?',
                        help="WorkshopLevelInfos.bytes filename.")
    args = parser.parse_args()

    if args.db is None:
        args.db = get_cache_filename("data.db")
    if args.FILE is None:
        args.FILE = get_profile_filename(
            "Levels/WorkshopLevels/WorkshopLevelInfos.bytes")

    conn = sqlite3.connect(args.db)

    c = conn.cursor()
    try:
        c.execute("DROP TABLE IF EXISTS level")
        c.execute("""CREATE TABLE level(
                  id, title, description, updated_date, published_date, tags,
                  author, authorid, path, published_by_user, upvotes, downvotes,
                  rating, unknown)""")
        c.execute("CREATE INDEX lvl_id_path ON level(id, path)")
        c.execute("CREATE INDEX lvl_path ON level(path)")
        c.execute("CREATE INDEX lvl_author ON level(author)")


# Path: distance/_nonlevel.py
# class WorkshopLevelInfos(BaseObject):
# 
#     type = 'WorkshopLevelInfos'
# 
# Path: distance_scripts/_common.py
# def get_cache_filename(filename):
#     return os.path.join(CACHE_PATH, filename)
# 
# def get_profile_filename(filename):
#     return os.path.join(PROFILE_PATH, filename)


# Path: distance_scripts/mklevelinfos.py
import argparse
import sqlite3
from distance import WorkshopLevelInfos
from ._common import get_cache_filename, get_profile_filename




def main():
    parser = argparse.ArgumentParser(
        description=__doc__)
    parser.add_argument("--db", help="database filename.")
    parser.add_argument("FILE", nargs='?',
                        help="WorkshopLevelInfos.bytes filename.")
    args = parser.parse_args()

    if args.db is None:
        args.db = get_cache_filename("data.db")
    if args.FILE is None:
        args.FILE = get_profile_filename(
            "Levels/WorkshopLevels/WorkshopLevelInfos.bytes")

    conn = sqlite3.connect(args.db)

    c = conn.cursor()
    try:
        c.execute("DROP TABLE IF EXISTS level")
        c.execute("""CREATE TABLE level(
                  id, title, description, updated_date, published_date, tags,
                  author, authorid, path, published_by_user, upvotes, downvotes,
                  rating, unknown)""")
        c.execute("CREATE INDEX lvl_id_path ON level(id, path)")
        c.execute("CREATE INDEX lvl_path ON level(path)")
        c.execute("CREATE INDEX lvl_author ON level(author)")


        infos = WorkshopLevelInfos(args.FILE)