import os
try:
    import tomllib
except ModuleNotFoundError:
    import tomli as tomllib

from __internal.license import check_license
from __internal.util import required_input

def init():
    pyproject = {
        "build-system": {
            "requires": ["nebula"]
        },
        "project": {}
    }
    basename = os.path.basename(os.getcwd())
    name = input("package name ({}): ".format(basename))
    version = input("version (0.1.0): ")
    description = input("description: ")
    repository = input("repository: ")
    author = input(__prompt="author: ", required_text="author is must be required.")
    while True:
        license = input("license: ")
        if license == "":
            break
        if  check_license(license):
            pyproject["project"]["license"] = license
            break
        print('Invalid license. The license can only be set to a license listed in the SPDX Open Source License Registry or "Proprietary" or "none".')
    print('License is set to "{}".'.format(license))
    if name == "":
        name = basename
    if version == "":
        version = "0.1.0"