# Copyright 2010-2021, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
#     * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#     * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

load(
    "//:build_defs.bzl",
    "mozc_cc_library",
    "mozc_cc_test",
    "mozc_select",
)

package(default_visibility = ["//visibility:private"])

mozc_cc_library(
    name = "config_handler",
    srcs = ["config_handler.cc"],
    hdrs = ["config_handler.h"],
    visibility = [
        "//:__subpackages__",
    ],
    deps = [
        "//base:clock",
        "//base:config_file_stream",
        "//base:hash",
        "//base:port",
        "//base:singleton",
        "//base:system_util",
        "//base:thread",
        "//base:version",
        "//base:vlog",
        "//base/strings:assign",
        "//protocol:config_cc_proto",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/time",
    ] + mozc_select(windows = [
        "//base/win32:wide_char",
        "//base/win32:win_sandbox",
    ]),
)

mozc_cc_test(
    name = "config_handler_test",
    size = "small",
    srcs = ["config_handler_test.cc"],
    data = ["//data/test/config:config_test_data"],
    deps = [
        ":config_handler",
        "//base:clock",
        "//base:clock_mock",
        "//base:file_util",
        "//base:system_util",
        "//base:thread",
        "//base/file:temp_dir",
        "//protocol:config_cc_proto",
        "//testing:gunit_main",
        "//testing:mozctest",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/random",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/time",
    ],
)

mozc_cc_library(
    name = "stats_config_util",
    srcs = ["stats_config_util.cc"],
    hdrs = ["stats_config_util.h"],
    visibility = [
        "//:__subpackages__",
    ],
    deps = [
        "//base:singleton",
    ] + mozc_select(
        android = [
            ":config_handler",
            "//protocol:config_cc_proto",
        ],
        ios = [
            "//base/mac:mac_util",
            "//base:system_util",
            "@com_google_absl//absl/strings",
            "@com_google_absl//absl/synchronization",
            "//base:file_util",
        ],
        macos = [
            "//base/mac:mac_util",
            "//base:system_util",
            "@com_google_absl//absl/strings",
            "@com_google_absl//absl/synchronization",
            "//base:file_util",
        ],
    ),
)

mozc_cc_test(
    name = "stats_config_util_test",
    size = "small",
    srcs = ["stats_config_util_test.cc"],
    deps = [
        ":stats_config_util",
        "//testing:gunit_main",
    ] + mozc_select(
        android = [
            ":config_handler",
            "//base/file:temp_dir",
            "//testing:mozctest",
            "//protocol:config_cc_proto",
        ],
        windows = [
            "//base:bits",
            "//base/win32:win_api_test_helper",
            "@com_google_absl//absl/base",
            "@com_google_absl//absl/container:flat_hash_map",
            "//base:singleton",
        ],
    ),
)

mozc_cc_library(
    name = "stats_config_util_mock",
    testonly = True,
    hdrs = ["stats_config_util_mock.h"],
    deps = [":stats_config_util"],
)

mozc_cc_library(
    name = "character_form_manager",
    srcs = ["character_form_manager.cc"],
    hdrs = ["character_form_manager.h"],
    visibility = [
        "//composer:__pkg__",
        "//prediction:__pkg__",
        "//rewriter:__pkg__",
        "//session:__pkg__",
    ],
    deps = [
        ":config_handler",
        "//base:bits",
        "//base:config_file_stream",
        "//base:number_util",
        "//base:singleton",
        "//base:util",
        "//base:vlog",
        "//base/strings:assign",
        "//base/strings:japanese",
        "//base/strings:unicode",
        "//protocol:config_cc_proto",
        "//storage:lru_storage",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

mozc_cc_test(
    name = "character_form_manager_test",
    size = "large",
    srcs = ["character_form_manager_test.cc"],
    deps = [
        ":character_form_manager",
        "//base:number_util",
        "//protocol:config_cc_proto",
        "//testing:gunit_main",
        "//testing:mozctest",
    ],
)
