load("//common:defs.bzl", "copy_file")
load("//dotnet:defs.bzl", "csharp_library", "devtools_version_targets", "framework", "generated_assembly_info", "nuget_pack")
load(
    "//dotnet:selenium-dotnet-version.bzl",
    "ASSEMBLY_COMPANY",
    "ASSEMBLY_COPYRIGHT",
    "ASSEMBLY_INFORMATIONAL_VERSION",
    "ASSEMBLY_PRODUCT",
    "ASSEMBLY_VERSION",
    "SE_VERSION",
)

exports_files([
    "WebDriver.csproj",
])

generated_assembly_info(
    name = "assembly-info",
    company = ASSEMBLY_COMPANY,
    copyright = ASSEMBLY_COPYRIGHT,
    description = "Selenium WebDriver API .NET Bindings",
    informational_version = ASSEMBLY_INFORMATIONAL_VERSION,
    product = ASSEMBLY_PRODUCT,
    title = "Selenium WebDriver",
    version = ASSEMBLY_VERSION,
)

csharp_library(
    name = "webdriver-netstandard2.0",
    srcs = [
        ":assembly-info",
    ] + glob([
        "**/*.cs",
    ]) + devtools_version_targets(),
    out = "WebDriver",
    internals_visible_to = [
        "WebDriver.Common.Tests",
    ],
    langversion = "12.0",
    nullable = "enable",
    resources = [
        "//javascript/atoms/fragments:find-elements.js",
        "//javascript/atoms/fragments:is-displayed.js",
        "//javascript/cdp-support:mutation-listener.js",
        "//javascript/webdriver/atoms:get-attribute.js",
        "//third_party/js/selenium:webdriver_json",
    ],
    target_frameworks = [
        "netstandard2.0",
    ],
    visibility = [
        "//dotnet:__subpackages__",
    ],
    deps = [
        framework("nuget", "NETStandard.Library"),
        framework("nuget", "Microsoft.Bcl.AsyncInterfaces"),
        framework("nuget", "System.Threading.Tasks.Extensions"),
        framework("nuget", "System.Memory"),
        framework("nuget", "System.Runtime.CompilerServices.Unsafe"),
        framework("nuget", "System.Text.Encodings.Web"),
        framework("nuget", "System.Text.Json"),
    ],
)

csharp_library(
    name = "webdriver-net8.0",
    srcs = [
        ":assembly-info",
    ] + glob([
        "**/*.cs",
    ]) + devtools_version_targets(),
    out = "WebDriver",
    defines = [
        "NET8_0_OR_GREATER",
    ],
    internals_visible_to = [
        "WebDriver.Common.Tests",
    ],
    langversion = "12.0",
    nullable = "enable",
    resources = [
        "//javascript/atoms/fragments:find-elements.js",
        "//javascript/atoms/fragments:is-displayed.js",
        "//javascript/cdp-support:mutation-listener.js",
        "//javascript/webdriver/atoms:get-attribute.js",
        "//third_party/js/selenium:webdriver_json",
    ],
    target_frameworks = [
        "net8.0",
    ],
    visibility = [
        "//dotnet:__subpackages__",
    ],
    deps = [
    ],
)

csharp_library(
    name = "webdriver-netstandard2.0-strongnamed",
    srcs = [
        ":assembly-info",
    ] + glob([
        "**/*.cs",
    ]) + devtools_version_targets(),
    out = "WebDriver.StrongNamed",
    keyfile = "//dotnet:Selenium.snk",
    langversion = "12.0",
    nullable = "enable",
    resources = [
        "//javascript/atoms/fragments:find-elements.js",
        "//javascript/atoms/fragments:is-displayed.js",
        "//javascript/cdp-support:mutation-listener.js",
        "//javascript/webdriver/atoms:get-attribute.js",
        "//third_party/js/selenium:webdriver_json",
    ],
    target_frameworks = [
        "netstandard2.0",
    ],
    visibility = [
        "//dotnet:__subpackages__",
    ],
    deps = [
        framework("nuget", "NETStandard.Library"),
        framework("nuget", "Microsoft.Bcl.AsyncInterfaces"),
        framework("nuget", "System.Threading.Tasks.Extensions"),
        framework("nuget", "System.Memory"),
        framework("nuget", "System.Runtime.CompilerServices.Unsafe"),
        framework("nuget", "System.Text.Encodings.Web"),
        framework("nuget", "System.Text.Json"),
    ],
)

csharp_library(
    name = "webdriver-net8.0-strongnamed",
    srcs = [
        ":assembly-info",
    ] + glob([
        "**/*.cs",
    ]) + devtools_version_targets(),
    out = "WebDriver.StrongNamed",
    defines = [
        "NET8_0_OR_GREATER",
    ],
    keyfile = "//dotnet:Selenium.snk",
    langversion = "12.0",
    nullable = "enable",
    resources = [
        "//javascript/atoms/fragments:find-elements.js",
        "//javascript/atoms/fragments:is-displayed.js",
        "//javascript/cdp-support:mutation-listener.js",
        "//javascript/webdriver/atoms:get-attribute.js",
        "//third_party/js/selenium:webdriver_json",
    ],
    target_frameworks = [
        "net8.0",
    ],
    visibility = [
        "//dotnet:__subpackages__",
    ],
    deps = [
    ],
)

copy_file(
    name = "readme",
    src = "//dotnet/src/webdriver/assets:README.md",
    out = "README.md",
)

copy_file(
    name = "props",
    src = "//dotnet/src/webdriver/assets:Selenium.WebDriver.targets",
    out = "Selenium.WebDriver.targets",
)

copy_file(
    name = "transitive-props",
    src = "//dotnet/src/webdriver/assets:Selenium.WebDriver.targets",
    out = "transitive.Selenium.WebDriver.targets",
)

copy_file(
    name = "manager-linux",
    src = "//common/manager:selenium-manager-linux",
    out = "manager/linux/selenium-manager",
    visibility = ["//dotnet/test/common:__pkg__"],
)

copy_file(
    name = "manager-macos",
    src = "//common/manager:selenium-manager-macos",
    out = "manager/macos/selenium-manager",
    visibility = ["//dotnet/test/common:__pkg__"],
)

copy_file(
    name = "manager-windows",
    src = "//common/manager:selenium-manager-windows",
    out = "manager/windows/selenium-manager.exe",
    visibility = ["//dotnet/test/common:__pkg__"],
)

nuget_pack(
    name = "webdriver-pack",
    files = {
        "//common/images:selenium_logo_small.png": "icon.png",
        "//common/manager:selenium-manager-linux": "manager/linux/selenium-manager",
        "//common/manager:selenium-manager-macos": "manager/macos/selenium-manager",
        "//common/manager:selenium-manager-windows": "manager/windows/selenium-manager.exe",
        ":readme": "README.md",
        ":props": "build/Selenium.WebDriver.targets",
        ":transitive-props": "buildTransitive/Selenium.WebDriver.targets",
    },
    id = "Selenium.WebDriver",
    libs = {
        ":webdriver-net8.0": "WebDriver",
        ":webdriver-netstandard2.0": "WebDriver",
    },
    nuspec_template = "Selenium.WebDriver.nuspec",
    tags = [
        "block-network",
    ],
    version = SE_VERSION,
    visibility = [
        "//dotnet:__subpackages__",
    ],
)

nuget_pack(
    name = "webdriver-strongnamed-pack",
    files = {
        "//common/images:selenium_logo_small.png": "icon.png",
        "//common/manager:selenium-manager-linux": "manager/linux/selenium-manager",
        "//common/manager:selenium-manager-macos": "manager/macos/selenium-manager",
        "//common/manager:selenium-manager-windows": "manager/windows/selenium-manager.exe",
        ":readme": "README.md",
        ":props": "build/Selenium.WebDriver.StrongNamed.targets",
        ":transitive-props": "buildTransitive/Selenium.WebDriver.StrongNamed.targets",
    },
    id = "Selenium.WebDriver.StrongNamed",
    libs = {
        ":webdriver-net8.0-strongnamed": "WebDriver.StrongNamed",
        ":webdriver-netstandard2.0-strongnamed": "WebDriver.StrongNamed",
    },
    nuspec_template = "Selenium.WebDriver.StrongNamed.nuspec",
    property_group_vars = {
        "BaseImagePath": "images",
        "BaseSeleniumManagerPath": "manager",
    },
    tags = [
        "block-network",
    ],
    version = SE_VERSION,
    visibility = [
        "//dotnet:__subpackages__",
    ],
)
