# 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.
"""Adapts REAF features into observations exposed by the environment."""

import abc
from collections.abc import Mapping
from gdm_robotics.interfaces import types as gdmr_types
import tree


class ObservationSpaceAdapter(abc.ABC):
  """Adapts REAF features into observations exposed by the environment.

  Implementations of this interface are responsible for converting the features
  generated by the REAF task layer logic (i.e. dictionary of tensors) into the
  more generic `observation` structure exposed by the environment.
  """

  @abc.abstractmethod
  def observations_from_features(
      self, features: Mapping[str, gdmr_types.ArrayType]
  ) -> tree.Structure[gdmr_types.ArrayType]:
    """Converts the REAF features into the environment observations."""

  @abc.abstractmethod
  def observation_spec(self) -> gdmr_types.ObservationSpec:
    """Returns the observation spec."""

  @abc.abstractmethod
  def task_features_keys(self) -> set[str]:
    """Returns the task features keys that will be converted by this adapter."""
