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 { createThawAccountInstruction } from '@solarti/spl-token';
import { isSigner, useOperation, } from '../../../types';
import { TransactionBuilder } from '../../../utils';
// -----------------
// Operation
// -----------------
const Key = 'ThawTokensOperation';
/**
 * Thaws a token account.
 *
 * ```ts
 * await metaplex.tokens().thaw({ mintAddress, freezeAuthority });
 * ```
 *
 * @group Operations
 * @category Constructors
 */
export const thawTokensOperation = useOperation(Key);
/**
 * @group Operations
 * @category Handlers
 */
export const thawTokensOperationHandler = {
    handle(operation, metaplex, scope) {
        return __awaiter(this, void 0, void 0, function* () {
            return thawTokensBuilder(metaplex, operation.input, scope).sendAndConfirm(metaplex, scope.confirmOptions);
        });
    },
};
/**
 * Thaws a token account.
 *
 * ```ts
 * const transactionBuilder = metaplex.tokens().builders().thaw({ mintAddress, freezeAuthority });
 * ```
 *
 * @group Transaction Builders
 * @category Constructors
 */
export const thawTokensBuilder = (metaplex, params, options = {}) => {
    var _a;
    const { programs, payer = metaplex.rpc().getDefaultFeePayer() } = options;
    const { mintAddress, tokenOwner = metaplex.identity().publicKey, tokenAddress, multiSigners = [], freezeAuthority, } = params;
    const [authorityPublicKey, signers] = isSigner(freezeAuthority)
        ? [freezeAuthority.publicKey, [freezeAuthority]]
        : [freezeAuthority, multiSigners];
    const tokenProgram = metaplex.programs().getToken(programs);
    const tokenAddressOrAta = tokenAddress !== null && tokenAddress !== void 0 ? tokenAddress : metaplex.tokens().pdas().associatedTokenAccount({
        mint: mintAddress,
        owner: tokenOwner,
        programs,
    });
    return TransactionBuilder.make()
        .setFeePayer(payer)
        .add({
        instruction: createThawAccountInstruction(tokenAddressOrAta, mintAddress, authorityPublicKey, multiSigners, tokenProgram.address),
        signers,
        key: (_a = params.instructionKey) !== null && _a !== void 0 ? _a : 'thawTokens',
    });
};
//# sourceMappingURL=thawTokens.js.map