load("//cuttlefish/bazel:rules.bzl", "cf_cc_binary", "cf_cc_library", "cf_cc_test")

package(
    default_visibility = ["//:android_cuttlefish"],
)

cf_cc_library(
    name = "clearcut_protos",
    srcs = ["clearcut_protos.cc"],
    hdrs = ["clearcut_protos.h"],
    deps = [
        "//external_proto:cf_log_cc_proto",
        "//external_proto:clientanalytics_cc_proto",
        "//external_proto:log_source_enum_cc_proto",
    ],
)

cf_cc_library(
    name = "debug_reader",
    srcs = ["debug_reader.cc"],
    hdrs = ["debug_reader.h"],
    deps = [
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/result",
        "//external_proto:cf_log_cc_proto",
        "@protobuf",
    ],
)

cf_cc_library(
    name = "events",
    srcs = ["events.cc"],
    hdrs = ["events.h"],
    deps = [
        "//cuttlefish/host/commands/metrics:clearcut_protos",
        "//cuttlefish/host/commands/metrics:send",
        "//cuttlefish/host/commands/metrics:utils",
        "//cuttlefish/host/libs/config:vmm_mode",
        "//external_proto:cf_log_cc_proto",
        "//external_proto:cf_metrics_event_cc_proto",
        "//external_proto:clientanalytics_cc_proto",
        "@abseil-cpp//absl/log",
        "@protobuf//:timestamp_cc_proto",
    ],
)

cf_cc_binary(
    name = "metrics",
    srcs = [
        "host_receiver.cc",
        "host_receiver.h",
        "metrics.cc",
    ],
    deps = [
        "//cuttlefish/common/libs/fs",
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/common/libs/utils:tee_logging",
        "//cuttlefish/host/commands/metrics:events",
        "//cuttlefish/host/commands/metrics:utils",
        "//cuttlefish/host/libs/config:cuttlefish_config",
        "//cuttlefish/host/libs/config:vmm_mode",
        "//cuttlefish/host/libs/log_names",
        "//cuttlefish/host/libs/metrics",
        "//cuttlefish/host/libs/metrics:metrics_headers",
        "//cuttlefish/host/libs/msg_queue",
        "//external_proto:cf_log_cc_proto",
        "//libbase",
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/log:check",
        "@fruit",
        "@gflags",
        "@jsoncpp",
        "@protobuf",
    ],
)

cf_cc_library(
    name = "metrics_conversion",
    srcs = [
        "metrics_conversion.cc",
    ],
    hdrs = [
        "metrics_conversion.h",
    ],
    deps = [
        "//cuttlefish/result",
        "//external_proto:clientanalytics_cc_proto",
        "//external_proto:log_source_enum_cc_proto",
    ],
)

cf_cc_library(
    name = "metrics_flags",
    srcs = [
        "metrics_flags.cc",
    ],
    hdrs = [
        "metrics_flags.h",
    ],
    deps = [
        "//cuttlefish/common/libs/utils:base64",
        "//cuttlefish/flag_parser",
        "//cuttlefish/host/libs/metrics:metrics_environment",
        "//cuttlefish/result",
    ],
)

cf_cc_library(
    name = "metrics_transmission",
    srcs = [
        "metrics_transmission.cc",
    ],
    hdrs = [
        "metrics_transmission.h",
    ],
    deps = [
        "//cuttlefish/host/libs/metrics:metrics_environment",
        "//cuttlefish/host/libs/web/http_client",
        "//cuttlefish/host/libs/web/http_client:curl_global_init",
        "//cuttlefish/host/libs/web/http_client:curl_http_client",
        "//cuttlefish/host/libs/web/http_client:http_string",
        "//cuttlefish/result",
        "//external_proto:clientanalytics_cc_proto",
    ],
)

cf_cc_binary(
    name = "metrics_transmitter",
    srcs = [
        "metrics_transmitter.cc",
    ],
    deps = [
        "//cuttlefish/common/libs/utils:tee_logging",
        "//cuttlefish/host/commands/metrics:debug_reader",
        "//cuttlefish/host/commands/metrics:metrics_conversion",
        "//cuttlefish/host/commands/metrics:metrics_flags",
        "//cuttlefish/host/commands/metrics:metrics_transmission",
        "//cuttlefish/result",
        "//external_proto:clientanalytics_cc_proto",
        "@abseil-cpp//absl/log",
    ],
)

cf_cc_library(
    name = "send",
    srcs = ["send.cc"],
    hdrs = ["send.h"],
    deps = [
        "//cuttlefish/host/libs/metrics:metrics_headers",
        "//cuttlefish/host/libs/web/http_client",
        "//cuttlefish/host/libs/web/http_client:curl_global_init",
        "//cuttlefish/host/libs/web/http_client:curl_http_client",
        "//cuttlefish/host/libs/web/http_client:http_string",
        "//cuttlefish/result",
        "//libbase",
        "@abseil-cpp//absl/log",
    ],
)

cf_cc_library(
    name = "utils",
    srcs = ["utils.cc"],
    hdrs = ["utils.h"],
    deps = [
        "//libbase",
        "@abseil-cpp//absl/log",
    ],
)

cf_cc_test(
    name = "utils_test",
    srcs = ["utils_tests.cpp"],
    deps = ["//cuttlefish/host/commands/metrics:utils"],
)
