/*
 * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
 *
 * 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.
 */

import { Subscription } from "rxjs";
import { UnsubscribableWrapper } from "./UnsubscribableWrapper.js";

/**
 * Implementation of the public ObservableClient interface.
 * - Delegates all operations to the Store for consistency
 * - Serves as the entry point for reactive data management
 * - Ensures proper method binding and API exposure
 *
 * @internal
 */
export class ObservableClientImpl {
  constructor(store) {
    this.__experimentalStore = store;
    this.applyAction = store.applyAction.bind(store);
    this.validateAction = store.validateAction.bind(store);
  }
  observeObject = (apiName, pk, options, subFn) => {
    return this.__experimentalStore.objects.observe({
      ...options,
      apiName,
      pk
    },
    // cast to cross typed to untyped barrier
    subFn);
  };
  observeList = (options, subFn) => {
    return this.__experimentalStore.lists.observe(options,
    // cast to cross typed to untyped barrier
    subFn);
  };
  observeAggregation = (options, subFn) => {
    return this.__experimentalStore.aggregations.observe(options, subFn);
  };
  observeLinks = (objects, linkName, options, subFn) => {
    // Convert to array if single object provided
    const objectsArray = Array.isArray(objects) ? objects : [objects];
    const parentSub = new Subscription();
    for (const obj of objectsArray) {
      const querySubscription = this.__experimentalStore.links.observe({
        ...options,
        srcType: {
          type: "object",
          apiName: obj.$apiName
        },
        linkName,
        pk: obj.$primaryKey
      },
      // cast to cross typed to untyped barrier
      subFn);
      parentSub.add(querySubscription);
    }
    return new UnsubscribableWrapper(parentSub);
  };
  observeObjectSet(baseObjectSet, options, subFn) {
    return this.__experimentalStore.objectSets.observe({
      baseObjectSet,
      ...options
    },
    // cast to cross typed to untyped barrier
    subFn);
  }
  invalidateAll() {
    return this.__experimentalStore.invalidateAll();
  }
  invalidateObjects(objects) {
    return this.__experimentalStore.invalidateObjects(objects);
  }
  invalidateObjectType(type) {
    return this.__experimentalStore.invalidateObjectType(type, undefined);
  }
  canonicalizeWhereClause(where) {
    return this.__experimentalStore.whereCanonicalizer.canonicalize(where);
  }
}
//# sourceMappingURL=ObservableClientImpl.js.map