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 { TokenGpaBuilder } from '../../tokenModule';
import { useOperation, } from '../../../types';
// -----------------
// Operation
// -----------------
const Key = 'FindNftsByOwnerOperation';
/**
 * Finds multiple NFTs and SFTs by a given owner.
 *
 * ```ts
 * const nfts = await metaplex
 *   .nfts()
 *   .findAllByOwner({ owner };
 * ```
 *
 * @group Operations
 * @category Constructors
 */
export const findNftsByOwnerOperation = useOperation(Key);
/**
 * @group Operations
 * @category Handlers
 */
export const findNftsByOwnerOperationHandler = {
    handle: (operation, metaplex, scope) => __awaiter(void 0, void 0, void 0, function* () {
        const { programs } = scope;
        const { owner } = operation.input;
        const tokenProgram = metaplex.programs().getToken(programs);
        const mints = yield new TokenGpaBuilder(metaplex, tokenProgram.address)
            .selectMint()
            .whereOwner(owner)
            .whereAmount(1)
            .getDataAsPublicKeys();
        scope.throwIfCanceled();
        const nfts = yield metaplex.nfts().findAllByMintList({ mints }, scope);
        scope.throwIfCanceled();
        return nfts.filter((nft) => nft !== null);
    }),
};
//# sourceMappingURL=findNftsByOwner.js.map