text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.HelixClipApi = void 0;
  const tslib_1 = require("tslib");
  const common_1 = require("@twurple/common");
  const BaseApi_1 = require("../../BaseApi");
  const HelixPaginatedRequest_1 = require("../HelixPaginatedRequest");
  const HelixPaginatedResult_1 = require("../HelixPaginatedResult");
  const HelixPagination_1 = require("../HelixPagination");
  const HelixClip_1 = require("./HelixClip");
  /**
   * The Helix API methods that deal with clips.
   *
   * Can be accessed using `client.clips` on an {@ApiClient} instance.
   *
   * ## Example
   * ```ts
   * const api = new ApiClient(new StaticAuthProvider(clientId, accessToken));
   * const clipId = await api.clips.createClip({ channelId: '125328655' });
   * ```
   */
  let HelixClipApi = class HelixClipApi extends BaseApi_1.BaseApi {
      /**
       * Retrieves the latest clips for the specified broadcaster.
       *
       * @param user The broadcaster to fetch clips for.
       * @param filter
       *
       * @expandParams
       */
      async getClipsForBroadcaster(user, filter = {}) {
          return await this._getClips({
              ...filter,
              filterType: 'broadcaster_id',
              ids: common_1.extractUserId(user)
          });
      }
      /**
       * Creates a paginator for the latest clips for the specified broadcaster.
       *
       * @param user The broadcaster to fetch clips for.
       * @param filter
       *
       * @expandParams
       */
      getClipsForBroadcasterPaginated(user, filter = {}) {
          return this._getClipsPaginated({
              ...filter,
              filterType: 'broadcaster_id',
              ids: common_1.extractUserId(user)
          });
      }
      /**
       * Retrieves the latest clips for the specified game.
       *
       * @param gameId The game ID.
       * @param filter
       *
       * @expandParams
       */
      async getClipsForGame(gameId, filter = {}) {
          return await this._getClips({
              ...filter,
              filterType: 'game_id',
              ids: gameId
          });
      }
      /**
       * Creates a paginator for the latest clips for the specified game.
       *
       * @param gameId The game ID.
       * @param filter
       *
       * @expandParams
       */
      getClipsForGamePaginated(gameId, filter = {}) {
          return this._getClipsPaginated({
              ...filter,
              filterType: 'game_id',
              ids: gameId
          });
      }
      /**
       * Retrieves the clips identified by the given IDs.
       *
       * @param ids The clip IDs.
       */
      async getClipsByIds(ids) {
          const result = await this._getClips({
              filterType: 'id',
              ids
          });
          return result.data;
      }
      /**
       * Retrieves the clip identified by the given ID.
       *
       * @param id The clip ID.
       */
      async getClipById(id) {
          const clips = await this.getClipsByIds([id]);
          return clips.length ? clips[0] : null;
      }
      /**
       * Creates a clip of a running stream.
       *
       * Returns the ID of the clip.
       *
       * @expandParams
       */
      async createClip(params) {
          const { channelId, createAfterDelay = false } = params;
          const result = await this._client.callApi({
              type: 'helix',
              url: 'clips',
              method: 'POST',
              scope: 'clips:edit',
              query: {
                  broadcaster_id: channelId,
                  has_delay: createAfterDelay.toString()
              }
          });
          return result.data[0].id;
      }
      async _getClips(params) {
          const { filterType, ids, startDate, endDate, ...pagination } = params;
          if (!ids.length) {
              return { data: [] };
          }
          const result = await this._client.callApi({
              type: 'helix',
              url: 'clips',
              query: {
                  [filterType]: ids,
                  started_at: startDate,
                  ended_at: endDate,
                  ...HelixPagination_1.makePaginationQuery(pagination)
              }
          });
          return HelixPaginatedResult_1.createPaginatedResult(result, HelixClip_1.HelixClip, this._client);
      }
      _getClipsPaginated(params) {
          const { filterType, ids, startDate, endDate } = params;
          return new HelixPaginatedRequest_1.HelixPaginatedRequest({
              url: 'clips',
              query: {
                  [filterType]: ids,
                  started_at: startDate,
                  ended_at: endDate
              }
          }, this._client, data => new HelixClip_1.HelixClip(data, this._client));
      }
  };
  HelixClipApi = tslib_1.__decorate([
      common_1.rtfm('api', 'HelixClipApi')
  ], HelixClipApi);
  exports.HelixClipApi = HelixClipApi;
  