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 { toMetadataAccount } from '../accounts';
import { toMetadata } from '../models';
import { useOperation, } from '../../../types';
import { GmaBuilder } from '../../../utils';
// -----------------
// Operation
// -----------------
const Key = 'FindNftsByMintListOperation';
/**
 * Finds multiple NFTs and SFTs by a given list of mint addresses.
 *
 * ```ts
 * const nfts = await metaplex
 *   .nfts()
 *   .findAllByMintList({ mints: [...] };
 * ```
 *
 * @group Operations
 * @category Constructors
 */
export const findNftsByMintListOperation = useOperation(Key);
/**
 * @group Operations
 * @category Handlers
 */
export const findNftsByMintListOperationHandler = {
    handle: (operation, metaplex, scope) => __awaiter(void 0, void 0, void 0, function* () {
        const { commitment, programs } = scope;
        const { mints } = operation.input;
        const nftPdas = metaplex.nfts().pdas();
        const metadataPdas = mints.map((mint) => nftPdas.metadata({ mint, programs }));
        const metadataInfos = yield GmaBuilder.make(metaplex, metadataPdas, {
            commitment,
        }).get();
        scope.throwIfCanceled();
        return metadataInfos.map((account) => {
            if (!account.exists) {
                return null;
            }
            try {
                return toMetadata(toMetadataAccount(account));
            }
            catch (error) {
                return null;
            }
        });
    }),
};
//# sourceMappingURL=findNftsByMintList.js.map