import { MetadataV1GpaBuilder } from '../gpaBuilders.mjs';
import { useOperation } from '../../../types/Operation.mjs';

// -----------------
// Operation
// -----------------

const Key = 'FindNftsByUpdateAuthorityOperation';

/**
 * Finds multiple NFTs and SFTs by a given update authority.
 *
 * ```ts
 * const nfts = await metaplex
 *   .nfts()
 *   .findAllByUpdateAuthority({ updateAuthority };
 * ```
 *
 * @group Operations
 * @category Constructors
 */
const findNftsByUpdateAuthorityOperation = useOperation(Key);

/**
 * @group Operations
 * @category Types
 */

/**
 * @group Operations
 * @category Handlers
 */
const findNftsByUpdateAuthorityOperationHandler = {
  handle: async (operation, metaplex, scope) => {
    const {
      updateAuthority
    } = operation.input;
    const gpaBuilder = new MetadataV1GpaBuilder(metaplex, metaplex.programs().getTokenMetadata(scope.programs).address);
    const mints = await gpaBuilder.selectMint().whereUpdateAuthority(updateAuthority).getDataAsPublicKeys();
    scope.throwIfCanceled();
    const nfts = await metaplex.nfts().findAllByMintList({
      mints
    }, scope);
    scope.throwIfCanceled();
    return nfts.filter(nft => nft !== null);
  }
};

export { findNftsByUpdateAuthorityOperation, findNftsByUpdateAuthorityOperationHandler };
//# sourceMappingURL=findNftsByUpdateAuthority.mjs.map
