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 { createWithdrawInstruction } from '@metaplex-foundation/mpl-candy-guard';
import { useOperation, } from '../../../types';
import { TransactionBuilder } from '../../../utils';
// -----------------
// Operation
// -----------------
const Key = 'DeleteCandyGuardOperation';
/**
 * Deletes a Candy Guard account by withdrawing its rent-exempt balance.
 *
 * ```ts
 * await metaplex
 *   .candyMachines()
 *   .deleteCandyGuard({
 *     candyGuard,
 *     authority,
 *   };
 * ```
 *
 * @group Operations
 * @category Constructors
 */
export const deleteCandyGuardOperation = useOperation(Key);
/**
 * @group Operations
 * @category Handlers
 */
export const deleteCandyGuardOperationHandler = {
    handle(operation, metaplex, scope) {
        return __awaiter(this, void 0, void 0, function* () {
            return deleteCandyGuardBuilder(metaplex, operation.input, scope).sendAndConfirm(metaplex, scope.confirmOptions);
        });
    },
};
/**
 * Deletes a Candy Guard account by withdrawing its rent-exempt balance.
 *
 * ```ts
 * const transactionBuilder = await metaplex
 *   .candyMachines()
 *   .builders()
 *   .deleteCandyGuard({
 *     candyGuard,
 *     authority,
 *   });
 * ```
 *
 * @group Transaction Builders
 * @category Constructors
 */
export const deleteCandyGuardBuilder = (metaplex, params, options = {}) => {
    var _a;
    const { programs, payer = metaplex.rpc().getDefaultFeePayer() } = options;
    const { candyGuard, authority = metaplex.identity() } = params;
    const candyGuardProgram = metaplex.programs().getCandyGuard(programs);
    return TransactionBuilder.make()
        .setFeePayer(payer)
        .add({
        instruction: createWithdrawInstruction({
            candyGuard,
            authority: authority.publicKey,
        }, candyGuardProgram.address),
        signers: [authority],
        key: (_a = params.deleteCandyGuardInstructionKey) !== null && _a !== void 0 ? _a : 'deleteCandyGuard',
    });
};
//# sourceMappingURL=deleteCandyGuard.js.map