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 { CandyGuard as MplCandyGuard } from '@metaplex-foundation/mpl-candy-guard';
import { toCandyGuard } from '../models';
import { GpaBuilder } from '../../../utils';
// -----------------
// Operation
// -----------------
const Key = 'FindCandyGuardsByAuthorityOperation';
/**
 * Find all Candy Guards matching by a given authority.
 *
 * ```ts
 * const candyGuards = await metaplex
 *   .candyMachines()
 *   .findAllCandyGuardsByAuthority({ authority: new PublicKey('...') });
 * ```
 *
 * @group Operations
 * @category Constructors
 */
export const findCandyGuardsByAuthorityOperation = _findCandyGuardsByAuthorityOperation;
// eslint-disable-next-line @typescript-eslint/naming-convention
function _findCandyGuardsByAuthorityOperation(input) {
    return { key: Key, input };
}
_findCandyGuardsByAuthorityOperation.key = Key;
/**
 * @group Operations
 * @category Handlers
 */
export const findCandyGuardsByAuthorityOperationHandler = {
    handle: (operation, metaplex, scope) => __awaiter(void 0, void 0, void 0, function* () {
        const { authority } = operation.input;
        const { programs, commitment } = scope;
        const candyGuardProgram = metaplex.programs().getCandyGuard(programs);
        const query = MplCandyGuard.gpaBuilder(candyGuardProgram.address).addFilter('authority', authority);
        const gpaBuilder = new GpaBuilder(metaplex, candyGuardProgram.address);
        gpaBuilder.mergeConfig(Object.assign(Object.assign({}, query.config), { commitment }));
        return gpaBuilder.getAndMap((account) => toCandyGuard(account, metaplex));
    }),
};
//# sourceMappingURL=findCandyGuardsByAuthority.js.map