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 { findCandyMachineV2CreatorPda } from '../pdas';
import { useOperation, } from '../../../types';
// -----------------
// Operation
// -----------------
const Key = 'FindMintedNftsByCandyMachineV2Operation';
/**
 * Find all minted NFTs from a given Candy Machine address.
 *
 * ```ts
 * const nfts = await metaplex
 *   .candyMachinesV2()
 *   .findMintedNfts({ candyMachine };
 * ```
 *
 * @group Operations
 * @category Constructors
 */
export const findMintedNftsByCandyMachineV2Operation = useOperation(Key);
/**
 * @group Operations
 * @category Handlers
 */
export const findMintedNftsByCandyMachineV2OperationHandler = {
    handle: (operation, metaplex, scope) => __awaiter(void 0, void 0, void 0, function* () {
        const { candyMachine, version = 2 } = operation.input;
        const firstCreator = version === 2
            ? findCandyMachineV2CreatorPda(candyMachine)
            : candyMachine;
        const mintedNfts = yield metaplex
            .nfts()
            .findAllByCreator({ creator: firstCreator, position: 1 }, scope);
        return mintedNfts;
    }),
};
//# sourceMappingURL=findMintedNftsByCandyMachineV2.js.map