var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { MetadataV1GpaBuilder } from '../gpaBuilders';
import { useOperation, } from '../../../types';
// -----------------
// 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
 */
export const findNftsByUpdateAuthorityOperation = useOperation(Key);
/**
 * @group Operations
 * @category Handlers
 */
export const findNftsByUpdateAuthorityOperationHandler = {
    handle: (operation, metaplex, scope) => __awaiter(void 0, void 0, void 0, function* () {
        const { updateAuthority } = operation.input;
        const gpaBuilder = new MetadataV1GpaBuilder(metaplex, metaplex.programs().getTokenMetadata(scope.programs).address);
        const mints = yield gpaBuilder
            .selectMint()
            .whereUpdateAuthority(updateAuthority)
            .getDataAsPublicKeys();
        scope.throwIfCanceled();
        const nfts = yield metaplex.nfts().findAllByMintList({ mints }, scope);
        scope.throwIfCanceled();
        return nfts.filter((nft) => nft !== null);
    }),
};
//# sourceMappingURL=findNftsByUpdateAuthority.js.map