# Path: src/comparator/resource_database.py
# class ResourceDatabase:
#     # Create resource database for file-level and messasge-level resouce definitions.
#     # It has two dictionaries: types map and patterns map. Register a resource will put
#     # [type_str, resource_message] in types dict, and [pattern0, resource_message]
#     # [pattern1, ressource_message] (if it has multiple patterns) in patterns dict."""
#     def __init__(self):
#         self.types = {}
#         self.patterns = {}
# 
#     def register_resource(self, resource_with_location):
#         """Register a resource in the database."""
#         if not resource_with_location or not resource_with_location.value:
#             return
#         resource_message = resource_with_location.value
#         if not resource_message.type or not resource_message.pattern:
#             raise TypeError(
#                 "APIs must define a resource type and resource pattern for each resource in the API."
#             )
#         self.types[resource_message.type] = resource_with_location
#         self.patterns.update(
#             (pattern, resource_with_location) for pattern in resource_message.pattern
#         )
# 
#     def get_resource_by_type(self, resource_type):
#         """Query the resource by type. Return None if the resource is not existing."""
#         return self.types.get(resource_type, None)
# 
#     def get_parent_resources_by_child_type(self, child_type):
#         """Query the resources by child_type. Return [] if the parent resource is not existing."""
#         result = []
#         if not child_type:
#             return result
#         child_resource = self.get_resource_by_type(child_type)
#         # The child_type is not existing in the database.
#         if (
#             not child_resource
#             or not child_resource.value
#             or not child_resource.value.pattern
#         ):
#             return result
#         # For each child_type pattern, split the pattern by '/'
#         # and reconstruct the segments. If any parent pattern is existing
#         # in the database, put it in the result sequence.
#         # For example: `a/{a}` is the parent resource of `a/{a}/b{b}`
#         for child_pattern in child_resource.value.pattern:
#             pattern = ""
#             for segment in child_pattern.split("/"):
#                 if pattern != "":
#                     pattern = pattern + "/"
#                 pattern = pattern + segment
#                 parent = self.get_resource_by_pattern(pattern)
#                 # Check the parent resource is not child_resource itself.
#                 if parent and (parent.value.type != child_resource.value.type):
#                     result.append(parent)
#         return result
# 
#     def get_resource_by_pattern(self, pattern):
#         """Query the resource by pattern. Return None if the resource is not existing."""
#         return self.patterns.get(pattern, None)


from typing import Tuple, Sequence, Dict
from google.protobuf import descriptor_pb2 as desc
from src.comparator.resource_database import ResourceDatabase
from google.api import resource_pb2, client_pb2, annotations_pb2, field_behavior_pb2
from google.longrunning import operations_pb2  # type: ignore
import src.comparator.wrappers as wrappers
    return wrappers.Oneof(make_oneof_pb2(name))


def make_message_pb2(
    name: str,
    fields: tuple = (),
    nested_type: tuple = (),
    enum_type: tuple = (),
    options: desc.MessageOptions = None,
    **kwargs,
) -> desc.DescriptorProto:
    return desc.DescriptorProto(
        name=name,
        field=fields,
        nested_type=nested_type,
        enum_type=enum_type,
        options=options,
        **kwargs,
    )


def make_message(
    name: str = "my_message",
    fields: Sequence[wrappers.Field] = (),
    oneofs: Sequence[wrappers.Oneof] = (),
    nested_enums: Sequence[wrappers.Enum] = (),
    nested_messages: Sequence[wrappers.Message] = (),
    proto_file_name: str = "foo",
    locations: Sequence[desc.SourceCodeInfo.Location] = [],
    path: Tuple[int] = (),

# Path: src/comparator/resource_database.py
# class ResourceDatabase:
#     # Create resource database for file-level and messasge-level resouce definitions.
#     # It has two dictionaries: types map and patterns map. Register a resource will put
#     # [type_str, resource_message] in types dict, and [pattern0, resource_message]
#     # [pattern1, ressource_message] (if it has multiple patterns) in patterns dict."""
#     def __init__(self):
#         self.types = {}
#         self.patterns = {}
# 
#     def register_resource(self, resource_with_location):
#         """Register a resource in the database."""
#         if not resource_with_location or not resource_with_location.value:
#             return
#         resource_message = resource_with_location.value
#         if not resource_message.type or not resource_message.pattern:
#             raise TypeError(
#                 "APIs must define a resource type and resource pattern for each resource in the API."
#             )
#         self.types[resource_message.type] = resource_with_location
#         self.patterns.update(
#             (pattern, resource_with_location) for pattern in resource_message.pattern
#         )
# 
#     def get_resource_by_type(self, resource_type):
#         """Query the resource by type. Return None if the resource is not existing."""
#         return self.types.get(resource_type, None)
# 
#     def get_parent_resources_by_child_type(self, child_type):
#         """Query the resources by child_type. Return [] if the parent resource is not existing."""
#         result = []
#         if not child_type:
#             return result
#         child_resource = self.get_resource_by_type(child_type)
#         # The child_type is not existing in the database.
#         if (
#             not child_resource
#             or not child_resource.value
#             or not child_resource.value.pattern
#         ):
#             return result
#         # For each child_type pattern, split the pattern by '/'
#         # and reconstruct the segments. If any parent pattern is existing
#         # in the database, put it in the result sequence.
#         # For example: `a/{a}` is the parent resource of `a/{a}/b{b}`
#         for child_pattern in child_resource.value.pattern:
#             pattern = ""
#             for segment in child_pattern.split("/"):
#                 if pattern != "":
#                     pattern = pattern + "/"
#                 pattern = pattern + segment
#                 parent = self.get_resource_by_pattern(pattern)
#                 # Check the parent resource is not child_resource itself.
#                 if parent and (parent.value.type != child_resource.value.type):
#                     result.append(parent)
#         return result
# 
#     def get_resource_by_pattern(self, pattern):
#         """Query the resource by pattern. Return None if the resource is not existing."""
#         return self.patterns.get(pattern, None)


# Path: test/tools/mock_descriptors.py
from typing import Tuple, Sequence, Dict
from google.protobuf import descriptor_pb2 as desc
from src.comparator.resource_database import ResourceDatabase
from google.api import resource_pb2, client_pb2, annotations_pb2, field_behavior_pb2
from google.longrunning import operations_pb2  # type: ignore
import src.comparator.wrappers as wrappers

    return wrappers.Oneof(make_oneof_pb2(name))


def make_message_pb2(
    name: str,
    fields: tuple = (),
    nested_type: tuple = (),
    enum_type: tuple = (),
    options: desc.MessageOptions = None,
    **kwargs,
) -> desc.DescriptorProto:
    return desc.DescriptorProto(
        name=name,
        field=fields,
        nested_type=nested_type,
        enum_type=enum_type,
        options=options,
        **kwargs,
    )


def make_message(
    name: str = "my_message",
    fields: Sequence[wrappers.Field] = (),
    oneofs: Sequence[wrappers.Oneof] = (),
    nested_enums: Sequence[wrappers.Enum] = (),
    nested_messages: Sequence[wrappers.Message] = (),
    proto_file_name: str = "foo",
    locations: Sequence[desc.SourceCodeInfo.Location] = [],
    path: Tuple[int] = (),

    resource_database: ResourceDatabase = None,