LICENSES = {
    "Apache-2.0",
    "BSD-2-Clause",
    "BSD-3-Clause",
    "BSD-4-Clause",
    "MIT",
    "PSF",
    "MPL-2.0",
    "LGPL",
    "wxWindows Library License",
    "Historical Permission Notice and Disclaimer",
    "The Unlicense",
    # special cases
    "Clarabot Limited Review License",
    "GPL with classpath-exception",  # this is fine to be used as a runtime
}
LICENSE_ALIASES = {
    "Apache 2.0": "Apache-2.0",
    "Apache 2": "Apache-2.0",
    "Apache License 2.0": "Apache-2.0",
    "http://www.apache.org/licenses/LICENSE-2.0": "Apache-2.0",
    "MIT license": "MIT",
    "MIT License": "MIT",
    "PSF License": "PSF",
    "The Unlicense (Unlicense)": "The Unlicense",
    "wxWindows Library License (https://opensource.org/licenses/wxwindows.php)": "wxWindows Library License",
    "HPND": "Historical Permission Notice and Disclaimer",
}


class Dependency(object):
    def __init__(self, name, license_name, license_text, author, author_email, home_url):
        license_name = LICENSE_ALIASES.get(license_name, license_name)
        assert name
        assert license_name in LICENSES, f"{name} {license_name!r}"
        assert license_text, f"No license text: {name}"

        self.name = name  # software program or library distribution name
        self.license_name = license_name  # normalised for grouping
        self.license_text = license_text  # raw as it was distributed ()
        # these are optional, they might be embedded in the license text
        self.author = author
        self.author_email = author_email
        self.home_url = home_url

        self.dependency_names = []

    def format(self):
        parts = [self.name]
        # author data could be used here
        if self.home_url:
            parts.append(self.home_url)
        parts.append(self.license_text)
        return "\n".join(parts)
