import * as tsplus_module_1 from "@tsplus/stdlib/collections/List/from";
import * as tsplus_module_2 from "@effect/core/stm/TRef/operations/unsafeGet";
import * as tsplus_module_3 from "@tsplus/stdlib/structure/Equals";
import * as tsplus_module_4 from "@tsplus/stdlib/collections/ImmutableQueue/size";
import * as tsplus_module_5 from "@tsplus/stdlib/collections/List/definition";
import * as tsplus_module_6 from "@tsplus/stdlib/collections/ImmutableQueue/appendAll";
import * as tsplus_module_7 from "@effect/core/stm/TRef/operations/unsafeSet";
import * as tsplus_module_8 from "@effect/core/stm/TQueue/definition";
import * as tsplus_module_9 from "@tsplus/stdlib/collections/Collection/functions";
import * as tsplus_module_10 from "@tsplus/stdlib/collections/ImmutableQueue/drop";
import * as tsplus_module_11 from "@effect/core/stm/STM/operations/effect";
import { STMInterruptException, STMRetryException } from "@effect/core/stm/STM";
import { concreteTQueue } from "@effect/core/stm/TQueue/operations/_internal/InternalTQueue";
/**
 * Offers all of the specified values to the queue, returning whether they
 * were offered to the queue.
 *
 * @tsplus fluent ets/TQueue offerAll
 */

export function offerAll_(self, as0) {
  void 0;
  const as = tsplus_module_1.from(as0);
  return tsplus_module_11.effect((journal, fiberId) => {
    const queue = tsplus_module_2.unsafeGet_(self.ref, journal);

    if (tsplus_module_3.equals(queue, null)) {
      throw new STMInterruptException(fiberId);
    }

    if (tsplus_module_4.size(queue) + tsplus_module_5.length(as) <= self.capacity) {
      tsplus_module_7.unsafeSet_(self.ref, tsplus_module_6.appendAll_(queue, as), journal);
      return true;
    }

    switch (self.strategy) {
      case tsplus_module_8.BackPressure:
        throw new STMRetryException();

      case tsplus_module_8.Dropping:
        {
          const forQueue = tsplus_module_9.take_(as, self.capacity - tsplus_module_4.size(queue));
          tsplus_module_7.unsafeSet_(self.ref, tsplus_module_6.appendAll_(queue, forQueue), journal);
          return false;
        }

      case tsplus_module_8.Sliding:
        {
          const forQueue = tsplus_module_1.from(tsplus_module_9.take_(as, self.capacity));
          const toDrop = tsplus_module_4.size(queue) + tsplus_module_5.length(forQueue) - self.capacity;
          tsplus_module_7.unsafeSet_(self.ref, tsplus_module_6.appendAll_(tsplus_module_10.drop_(queue, toDrop), forQueue), journal);
          return true;
        }
    }

    return false;
  });
}
/**
 * Offers all of the specified values to the queue, returning whether they
 * were offered to the queue.
 *
 * @tsplus static ets/TQueue/Aspects offerAll
 */

export const offerAll = as0 => self => offerAll_(self, as0);
//# sourceMappingURL=offerAll.mjs.map