load("@rules_python//python:defs.bzl", "py_binary")
load("@py_deps//:requirements.bzl", "requirement")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@bazel_skylib//lib:selects.bzl", "selects")
load(":python_lib.bzl", "copy_python_lib")

py_binary(
    name = "genbackend",
    srcs = [
        "genbackend.py",
    ],
    deps = [
        requirement("black"),
        "//pylib/anki/_vendor:stringcase",
        requirement("protobuf"),
        "//pylib/anki:proto",
    ],
)

genrule(
    name = "rsbackend_gen",
    outs = ["generated.py"],
    cmd = "$(location genbackend) $@",
    tools = ["genbackend"],
)

py_binary(
    name = "genfluent",
    srcs = [
        "genfluent.py",
    ],
    deps = [
        requirement("black"),
        "//pylib/anki/_vendor:stringcase",
    ],
)

genrule(
    name = "fluent_gen",
    outs = ["fluent.py"],
    cmd = "$(location genfluent) $(location //rslib/i18n:strings.json) $@",
    tools = [
        "genfluent",
        "//rslib/i18n:strings.json",
    ],
)

copy_python_lib(
    name = "rsbridge",
    src = "//pylib/rsbridge",
)

_py_srcs = [
    "genbackend.py",
    "__init__.py",
]

# for format check
filegroup(
    name = "py_source_files",
    srcs = _py_srcs,
    visibility = [
        "//pylib:__subpackages__",
    ],
)

filegroup(
    name = "_backend",
    srcs = [
        "__init__.py",
        "rsbridge.pyi",
        ":fluent_gen",
        ":rsbackend_gen",
        ":rsbridge",
    ],
    visibility = ["//pylib:__subpackages__"],
)
