from pathlib import Path

from dev_tools.build.licensing.common import Dependency


def get_bundled_dependencies(deps_path: Path):
    openjdk_license = f"\n{'-'*80}\n".join(
        [
            (deps_path / "jre/legal/java.base/LICENSE").read_text(encoding="utf-8"),
            (deps_path / "jre/legal/java.base/ADDITIONAL_LICENSE_INFO").read_text(encoding="utf-8"),
            (deps_path / "jre/legal/java.base/ASSEMBLY_EXCEPTION").read_text(encoding="utf-8"),
        ]
    )
    solr_license = f"\n{'-'*80}\n".join(
        [
            (deps_path / "solr/LICENSE.txt").read_text(encoding="utf-8"),
            (deps_path / "solr/NOTICE.txt").read_text(encoding="utf-8"),
        ]
    )
    tika_license = f"\n{'-'*80}\n".join(
        [
            (deps_path / "tika/LICENSE.txt").read_text(encoding="utf-8"),
            (deps_path / "tika/NOTICE.txt").read_text(encoding="utf-8"),
        ]
    )
    return [
        # a java VM runtime for some dependencies
        Dependency(
            "openjdk",
            "GPL with classpath-exception",
            openjdk_license,
            None,
            None,
            "https://openjdk.java.net/",
        ),
        Dependency(
            "Solr",
            "Apache 2.0",
            solr_license,
            None,
            None,
            "https://solr.apache.org/",
        ),
        Dependency(
            "Tika",
            "Apache 2.0",
            tika_license,
            None,
            None,
            "https://tika.apache.org/",
        ),
    ]
