# Copyright 2025 Google LLC
#
# 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
#
# https://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.
"""Produces additional features to be exposed by the task logic layer."""

import abc
from collections.abc import Mapping

from dm_env import specs
from gdm_robotics.interfaces import types as gdmr_types


class FeaturesProducer(abc.ABC):
  """Produces additional features to be exposed by the task logic layer."""

  @property
  @abc.abstractmethod
  def name(self) -> str:
    """Returns a unique string identifier for this object."""

  @abc.abstractmethod
  def produce_features(
      self, required_features: Mapping[str, gdmr_types.ArrayType]
  ) -> Mapping[str, gdmr_types.ArrayType]:
    """Produces additional features for the environment.

    Args:
      required_features: Measurements and features generated by previous
        producers in the processing chain that are required by this processor,
        i.e. with keys specified by `required_features_keys`.

    Returns additional features that will be added to the global measurements
      and features dictionary.
    """

  @abc.abstractmethod
  def produced_features_spec(self) -> Mapping[str, specs.Array]:
    """Returns the spec of the features produced by this producer."""

  @abc.abstractmethod
  def required_features_keys(self) -> set[str]:
    """Returns the keys that are required to produce the new features."""

  def reset(self) -> None:
    """Resets the internal state of the feature producer."""
    ...
