import os
import platform
import dependencies.revision as revision

machine = platform.machine().lower()
machine = "x86_64" if machine == "amd64" else machine
system = platform.system().lower()


deps = {
    'third_party/abseil-cpp': {
        'type': 'git',
        'url': 'https://flutter.googlesource.com/third_party/abseil-cpp',
        'ignore_in_git': True,
        'commit': revision.ABSEIL_CPP,
        'condition': system in [ 'darwin', 'windows', 'linux' ],
    },
    'third_party/angle': {
        'type': 'git',
        'url': 'https://github.com/google/angle.git',
        'ignore_in_git': True,
        'commit': revision.ANGLE,
        'condition': system in [ 'darwin', 'linux', 'windows' ],
        "patches": [
            os.path.join(root_dir, 'patches', 'angle', '*.patch')
        ],
    },
    "third_party/angle/third_party/astc-encoder/src": {
        "type": "git",
        "url": "https://github.com/ARM-software/astc-encoder.git",
        "commit": revision.ASTC_ENCODER,
        "require":
        [
            "third_party/angle"
        ]
    },
    "third_party/angle/third_party/wayland": {
        "type": "git",
        "url": "https://chromium.googlesource.com/external/anongit.freedesktop.org/git/wayland/wayland.git",
        "commit": revision.WAYLAND,
        'condition': system == "linux",
        "require":
        [
            "third_party/angle"
        ]
    },
    'third_party/expat': {
        "type": "git",
        "url": "https://flutter.googlesource.com/third_party/expat.git",
        "commit": revision.EXPAT,
        "patches": [
            os.path.join(root_dir, 'patches', 'expat', '*.patch')
        ],
        "ignore_in_git": True,
    },
    "third_party/glfw": {
        "type": "git",
        "url": "https://fuchsia.googlesource.com/third_party/glfw.git",
        "commit": revision.GLFW
    },
    'third_party/gtest-parallel': {
        "type": "git",
        "url": "https://github.com/google/gtest-parallel.git",
        "commit": revision.GTEST_PARALLEL,
        "ignore_in_git": True,
    },
    'third_party/gyp': {
        "type": "git",
        "url": "https://chromium.googlesource.com/external/gyp.git",
        "commit": revision.GYP,
        "ignore_in_git": True,
    },
    'third_party/harfbuzz': {
        'type': 'git',
        'url': 'https://github.com/harfbuzz/harfbuzz.git',
        'commit': revision.HARFBUZZ,
        "patches": [
            os.path.join(root_dir, 'patches', 'harfbuzz', '*.patch')
        ],
        "ignore_in_git": True,
    },
    "third_party/icu": {
        "type": "git",
        "url": "https://chromium.googlesource.com/chromium/deps/icu.git",
        "commit": revision.ICU,
        "patches": [
            os.path.join(root_dir, 'patches', 'icu', '*.patch')
        ],
        "ignore_in_git": True,
    },
    "third_party/libjpeg-turbo": {
        "type": "git",
        "url": "https://fuchsia.googlesource.com/third_party/libjpeg-turbo.git",
        "commit": revision.LIBJPEG_TURBO,
        "patches": [
            os.path.join(root_dir, 'patches', 'libjpeg-turbo', '*.patch')
        ],
        "ignore_in_git": True,
    },
    'third_party/libpng': {
        'type': 'git',
        'url': 'https://flutter.googlesource.com/third_party/libpng.git',
        'commit': revision.LIBPNG,
        "patches": [
            os.path.join(root_dir, 'patches', 'libpng', '*.patch')
        ],
        "ignore_in_git": True,
    },
    "third_party/libwebp": {
        "type": "git",
        "url": "https://chromium.googlesource.com/webm/libwebp.git",
        "commit": revision.LIBWEBP,
        "ignore_in_git": True,
    },
    "third_party/nanopng": {
        "type": "git",
        "url": "https://gitlab.com/TSnake41/nanopng.git",
        "commit": "fa1bf5cf7ec3ad98e0be665acbb4b36c696ae059",
        "patches": os.path.join(root_dir, 'patches', 'nanopng', '0001-Adapt-nanopng-to-the-Skity-project.patch'),
        "ignore_in_git": True,
    },
    "third_party/skia": {
        "type": "git",
        "url": "https://skia.googlesource.com/skia.git",
        "commit": revision.SKIA,
        "patches": [
            os.path.join(root_dir, 'patches', 'skia', '*.patch')
        ],
        "ignore_in_git": True,
    },
    "third_party/swiftshader/": {
        "type": "git",
        "url": "https://swiftshader.googlesource.com/SwiftShader.git",
        "commit": revision.SWIFTSHADER,
        "patches": [
            os.path.join(root_dir, 'patches', 'swiftshader', '*.patch')
        ],
        "ignore_in_git": True,
    },
    "third_party/wuffs": {
        "type": "git",
        "url": "https://skia.googlesource.com/external/github.com/google/wuffs.git",
        "commit": revision.WUFFS,
        "ignore_in_git": True,
    },
    "third_party/vulkan_memory_allocator": {
        "type": "git",
        "url": "https://chromium.googlesource.com/external/github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git",
        "commit": revision.VULKAN_MEMORY_ALLOCATOR,
        "patches": [
            os.path.join(root_dir, 'patches', 'vulkan_memory_allocator', '*.patch')
        ],
        "ignore_in_git": True,
    },
    "third_party/vulkan-deps": {
        "type": "git",
        "url": "https://chromium.googlesource.com/vulkan-deps.git",
        "commit": revision.VULKAN_DEPS,
    },
    "third_party/vulkan-deps/vulkan-headers/src": {
        "type": "git",
        "url": "https://chromium.googlesource.com/external/github.com/KhronosGroup/Vulkan-Headers",
        "commit": revision.VULKAN_HEADERS,
        "require":
        [
            "third_party/vulkan-deps"
        ]
    },
    "third_party/vulkan-deps/vulkan-loader/src": {
        "type": "git",
        "url": "https://chromium.googlesource.com/external/github.com/KhronosGroup/Vulkan-Loader.git",
        "commit": revision.VULKAN_LOADER,
        "require": [
            "third_party/vulkan-deps"
        ],
        "patches": [
            os.path.join(root_dir, 'patches', 'vulkan-loader', '*.patch')
        ],
    },
    "third_party/vulkan-deps/vulkan-tools/src": {
        "type": "git",
        "url": "https://chromium.googlesource.com/external/github.com/KhronosGroup/Vulkan-Tools.git",
        "commit": revision.VULKAN_TOOLS,
        "require":
        [
            "third_party/vulkan-deps"
        ]
    },
    "third_party/vulkan-deps/spirv-tools/src": {
        "type": "git",
        "url": "https://chromium.googlesource.com/external/github.com/KhronosGroup/SPIRV-Tools.git",
        "commit": revision.SPIRV_TOOLS,
        "require":
        [
            "third_party/vulkan-deps"
        ]
    },
    "third_party/vulkan-deps/spirv-headers/src": {
        "type": "git",
        "url": "https://chromium.googlesource.com/external/github.com/KhronosGroup/SPIRV-Headers.git",
        "commit": revision.SPIRV_HEADERS,
        "require":
        [
            "third_party/vulkan-deps"
        ]
    },
    "third_party/vulkan-deps/spirv-cross/src":
    {
        "type": "git",
        "url": "https://chromium.googlesource.com/external/github.com/KhronosGroup/SPIRV-Cross.git",
        "commit": revision.SPIRV_CROSS,
        "require":
        [
            "third_party/vulkan-deps"
        ]
    },
    "third_party/vulkan-deps/glslang/src":
    {
        "type": "git",
        "url": "https://chromium.googlesource.com/external/github.com/KhronosGroup/glslang.git",
        "commit": revision.GLSLANG,
        "require":
        [
            "third_party/vulkan-deps"
        ]
    },
    'third_party/freetype2': {
        'type': 'git',
        'url': 'https://github.com/freetype/freetype.git',
        'commit': revision.FREETYPE2,
        "patches": [
            os.path.join(root_dir, 'patches', 'freetype2', '*.patch')
        ],
        "ignore_in_git": True,
    },
    "clay/third_party/glm": {
        "type": "git",
        "url": "https://github.com/g-truc/glm.git",
        "ignore_in_git": True,
        "commit": revision.GLM,
    },
    'clay/testing/resources': {
        "type": "http",
        'url': f"https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/clay/testing_res.zip",
        "ignore_in_git": True,
        "decompress": True,
    },
    'clay/shell/platform/windows/resources/chromium_cursors': {
        "type": "http",
        'url': f"https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/clay/chromium_cursors.zip",
        "ignore_in_git": True,
        "decompress": True,
        'condition': system == 'windows',
    },
    'clay/third_party/txt/third_party/fonts': {
        "type": "http",
        'url': f"https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/clay/roboto-bold.ttf.zip",
        "ignore_in_git": True,
        "decompress": True,
    },
    "third_party/skity": {
        "type": "solution",
        "url": "https://github.com/lynx-family/skity.git",
        "commit": revision.SKITY,
        "deps_file": "hab/DEPS",
        "ignore_in_git": True,
        "enable_lfs": False,
    },
    "third_party/textlayout": {
        "type": "git",
        "url": "https://github.com/lynx-family/lynx-textra.git",
        "commit": revision.TEXTRA,
        "deps_file": "DEPS",
        "ignore_in_git": True,
        "enable_lfs": False,
    },
    "third_party/ServalKit": {
        "type": "git",
        "url": "https://github.com/lynx-family/serval-kit.git",
        "commit": revision.SERVALKIT,
        "ignore_in_git": True,
        "condition": system in ['windows', 'darwin', 'linux'],
    },
}