load("//tools/lint:lint.bzl", "add_lint_tests")
load(
    "//tools/skylark:drake_cc.bzl",
    "drake_cc_googletest",
    "drake_cc_library",
    "drake_cc_package_library",
)

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

drake_cc_package_library(
    name = "planning",
    visibility = ["//visibility:public"],
    deps = [
        ":body_shape_description",
        ":collision_avoidance",
        ":collision_checker",
        ":collision_checker_context",
        ":collision_checker_params",
        ":distance_and_interpolation_provider",
        ":linear_distance_and_interpolation_provider",
        ":robot_clearance",
        ":robot_collision_type",
        ":robot_diagram",
        ":robot_diagram_builder",
        ":scene_graph_collision_checker",
        ":unimplemented_collision_checker",
        ":visibility_graph",
    ],
)

drake_cc_library(
    name = "body_shape_description",
    srcs = ["body_shape_description.cc"],
    hdrs = ["body_shape_description.h"],
    deps = [
        "//common:essential",
        "//geometry",
        "//multibody/plant",
    ],
)

drake_cc_library(
    name = "collision_avoidance",
    srcs = ["collision_avoidance.cc"],
    hdrs = ["collision_avoidance.h"],
    deps = [
        ":collision_checker",
    ],
)

drake_cc_library(
    name = "collision_checker",
    srcs = ["collision_checker.cc"],
    hdrs = [
        "collision_checker.h",
        "edge_measure.h",
    ],
    interface_deps = [
        ":body_shape_description",
        ":collision_checker_context",
        ":collision_checker_params",
        ":distance_and_interpolation_provider",
        ":robot_clearance",
        ":robot_collision_type",
        ":robot_diagram",
        "//common:essential",
        "//common:parallelism",
        "//geometry",
        "//multibody/plant",
    ],
    deps = [
        ":linear_distance_and_interpolation_provider",
        "@common_robotics_utilities",
    ],
)

drake_cc_library(
    name = "collision_checker_context",
    srcs = ["collision_checker_context.cc"],
    hdrs = ["collision_checker_context.h"],
    deps = [
        ":robot_diagram",
        "//common:essential",
    ],
)

drake_cc_library(
    name = "collision_checker_params",
    hdrs = ["collision_checker_params.h"],
    deps = [
        ":distance_and_interpolation_provider",
        ":robot_diagram",
        "//common:parallelism",
        "//multibody/tree:multibody_tree_indexes",
    ],
)

drake_cc_library(
    name = "distance_and_interpolation_provider",
    srcs = ["distance_and_interpolation_provider.cc"],
    hdrs = ["distance_and_interpolation_provider.h"],
    deps = [
        "//common:essential",
    ],
)

drake_cc_library(
    name = "linear_distance_and_interpolation_provider",
    srcs = ["linear_distance_and_interpolation_provider.cc"],
    hdrs = ["linear_distance_and_interpolation_provider.h"],
    interface_deps = [
        ":distance_and_interpolation_provider",
        "//multibody/plant",
    ],
    deps = [
        "//common:essential",
        "@common_robotics_utilities",
    ],
)

drake_cc_library(
    name = "robot_clearance",
    srcs = ["robot_clearance.cc"],
    hdrs = ["robot_clearance.h"],
    deps = [
        ":robot_collision_type",
        "//common:essential",
        "//multibody/tree:multibody_tree_indexes",
    ],
)

drake_cc_library(
    name = "robot_collision_type",
    hdrs = ["robot_collision_type.h"],
)

drake_cc_library(
    name = "robot_diagram",
    srcs = ["robot_diagram.cc"],
    hdrs = ["robot_diagram.h"],
    deps = [
        "//common:default_scalars",
        "//geometry:scene_graph",
        "//multibody/plant",
        "//systems/framework:diagram",
        "//systems/framework:diagram_builder",
    ],
)

drake_cc_library(
    name = "robot_diagram_builder",
    srcs = ["robot_diagram_builder.cc"],
    hdrs = ["robot_diagram_builder.h"],
    deps = [
        ":robot_diagram",
        "//common:default_scalars",
        "//geometry:scene_graph",
        "//multibody/parsing",
        "//multibody/plant",
        "//systems/framework:diagram_builder",
    ],
)

drake_cc_library(
    name = "scene_graph_collision_checker",
    srcs = ["scene_graph_collision_checker.cc"],
    hdrs = ["scene_graph_collision_checker.h"],
    interface_deps = [
        ":collision_checker",
        ":collision_checker_params",
    ],
    deps = [
        ":robot_diagram",
        "//geometry",
        "//multibody/plant",
    ],
)

drake_cc_library(
    name = "unimplemented_collision_checker",
    srcs = ["unimplemented_collision_checker.cc"],
    hdrs = ["unimplemented_collision_checker.h"],
    deps = [
        ":collision_checker",
        ":collision_checker_params",
    ],
)

drake_cc_library(
    name = "planning_test_helpers",
    testonly = True,
    srcs = ["test/planning_test_helpers.cc"],
    hdrs = ["test/planning_test_helpers.h"],
    visibility = ["//visibility:private"],
    deps = [
        ":collision_checker",
        ":robot_diagram_builder",
        "//multibody/parsing",
    ],
)

drake_cc_library(
    name = "visibility_graph",
    srcs = ["visibility_graph.cc"],
    hdrs = ["visibility_graph.h"],
    interface_deps = [
        ":collision_checker",
        "//common:parallelism",
    ],
    deps = [
        "@common_robotics_utilities",
    ],
)

# === test/ ===

drake_cc_googletest(
    name = "body_shape_description_test",
    deps = [
        ":body_shape_description",
        ":robot_diagram_builder",
        "//multibody/parsing",
        "//multibody/plant",
    ],
)

drake_cc_googletest(
    name = "collision_avoidance_test",
    deps = [
        ":collision_avoidance",
        ":robot_diagram_builder",
        ":unimplemented_collision_checker",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "collision_checker_test",
    # Running with multiple threads is an essential part of our test coverage.
    num_threads = 2,
    deps = [
        ":collision_checker",
        ":planning_test_helpers",
        ":unimplemented_collision_checker",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
        "@common_robotics_utilities",
    ],
)

drake_cc_googletest(
    name = "collision_checker_context_test",
    deps = [
        ":collision_checker_context",
        ":robot_diagram_builder",
    ],
)

drake_cc_googletest(
    name = "distance_and_interpolation_provider_test",
    deps = [
        ":distance_and_interpolation_provider",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
        "@common_robotics_utilities",
    ],
)

drake_cc_googletest(
    name = "linear_distance_and_interpolation_provider_test",
    data = [
        "//planning/test_utilities:collision_ground_plane.sdf",
        "//planning/test_utilities:flying_robot_base.sdf",
        "@drake_models//:iiwa_description",
        "@drake_models//:ycb",
    ],
    deps = [
        ":linear_distance_and_interpolation_provider",
        ":planning_test_helpers",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
        "@common_robotics_utilities",
    ],
)

drake_cc_googletest(
    name = "robot_clearance_test",
    deps = [
        ":robot_clearance",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "robot_collision_type_test",
    deps = [
        ":robot_collision_type",
    ],
)

drake_cc_googletest(
    name = "robot_diagram_test",
    data = [
        "@drake_models//:iiwa_description",
    ],
    deps = [
        ":robot_diagram",
        ":robot_diagram_builder",
        "//common/test_utilities:expect_throws_message",
        "//systems/primitives:shared_pointer_system",
    ],
)

drake_cc_googletest(
    name = "scene_graph_collision_checker_test",
    timeout = "moderate",
    data = [
        "@drake_models//:ycb",
    ],
    # Running with multiple threads is an essential part of our test coverage.
    num_threads = 2,
    deps = [
        ":linear_distance_and_interpolation_provider",
        ":planning_test_helpers",
        ":scene_graph_collision_checker",
        "//common/test_utilities:eigen_matrix_compare",
        "//planning/test_utilities:collision_checker_abstract_test_suite",
    ],
)

drake_cc_googletest(
    name = "visibility_graph_test",
    # Running with multiple threads is an essential part of our test coverage.
    num_threads = 2,
    deps = [
        ":robot_diagram_builder",
        ":scene_graph_collision_checker",
        ":visibility_graph",
        "//common/test_utilities:eigen_matrix_compare",
    ],
)

drake_cc_googletest(
    name = "unimplemented_collision_checker_test",
    deps = [
        ":robot_diagram_builder",
        ":unimplemented_collision_checker",
        "//common/test_utilities:expect_throws_message",
    ],
)

add_lint_tests()
