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 = 'FindNftsByCreatorOperation';
/**
 * Finds multiple NFTs and SFTs by their creator at a given position.
 *
 * ```ts
 * // Find all by first creator.
 * const nfts = await metaplex
 *   .nfts()
 *   .findAllByCreator({ creator };
 *
 * // Find all by second creator.
 * const nfts = await metaplex
 *   .nfts()
 *   .findAllByCreator({ creator, position: 2 };
 * ```
 *
 * @group Operations
 * @category Constructors
 */
export const findNftsByCreatorOperation = useOperation(Key);
/**
 * @group Operations
 * @category Handlers
 */
export const findNftsByCreatorOperationHandler = {
    handle: (operation, metaplex, scope) => __awaiter(void 0, void 0, void 0, function* () {
        const { programs } = scope;
        const { creator, position = 1 } = operation.input;
        const gpaBuilder = new MetadataV1GpaBuilder(metaplex, metaplex.programs().getTokenMetadata(programs).address);
        const mints = yield gpaBuilder
            .selectMint()
            .whereCreator(position, creator)
            .getDataAsPublicKeys();
        scope.throwIfCanceled();
        const nfts = yield metaplex.nfts().findAllByMintList({ mints }, scope);
        scope.throwIfCanceled();
        return nfts.filter((nft) => nft !== null);
    }),
};
//# sourceMappingURL=findNftsByCreator.js.map