# Copyright 2022 The TensorStore Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Defines information about analyzed Bazel targets."""

# pylint: disable=missing-function-docstring,relative-beyond-top-level

from typing import Any, List, Optional

from .bazel_target import TargetId
from .provider import Provider


class BuildSettingProvider(Provider):
  """Build setting value (i.e. flag value) corresponding to a Bazel target."""
  __slots__ = ("value",)

  def __init__(self, value: Any):
    self.value = value

  def __repr__(self):
    return f"{self.__class__.__name__}({repr(self.value)})"


class ConditionProvider(Provider):
  """Condition value corresponding to a Bazel target."""
  __slots__ = ("value",)

  def __init__(self, value: bool):
    self.value = value

  def __repr__(self):
    return f"{self.__class__.__name__}({self.value})"


class FilesProvider(Provider):
  """Files corresponding to a Bazel target."""

  __slots__ = ("paths",)

  def __init__(self, paths: List[str]):
    self.paths = paths

  def __repr__(self):
    return f"{self.__class__.__name__}({repr(self.paths)})"


class ProtoLibraryProvider(Provider):
  __slots__ = ("srcs", "deps", "strip_import_prefix")

  def __init__(self, srcs: List[TargetId], deps: List[TargetId],
               strip_import_prefix: Optional[str]):
    self.srcs = sorted(set(srcs))
    self.deps = sorted(set(deps))
    self.strip_import_prefix = strip_import_prefix

  def __repr__(self):
    return f"{self.__class__.__name__}({repr(self.srcs)}, {repr(self.deps)}, {repr(self.strip_import_prefix)})"
