'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var mplTokenMetadata = require('@metaplex-solarti/mpl-token-metadata');
var Operation = require('../../../types/Operation.cjs');
var TransactionBuilder = require('../../../utils/TransactionBuilder.cjs');

// -----------------
// Operation
// -----------------

const Key = 'UnverifyNftCreatorOperation';

/**
 * Unverifies the creator of an NFT or SFT.
 *
 * ```ts
 * await metaplex
 *   .nfts()
 *   .unverifyCreator({ mintAddress, creator };
 * ```
 *
 * @group Operations
 * @category Constructors
 */
const unverifyNftCreatorOperation = Operation.useOperation(Key);

/**
 * @group Operations
 * @category Types
 */

/**
 * @group Operations
 * @category Handlers
 */
const unverifyNftCreatorOperationHandler = {
  handle: async (operation, metaplex, scope) => {
    return unverifyNftCreatorBuilder(metaplex, operation.input, scope).sendAndConfirm(metaplex, scope.confirmOptions);
  }
};

// -----------------
// Builder
// -----------------

/**
 * @group Transaction Builders
 * @category Inputs
 */

/**
 * Unverifies the creator of an NFT or SFT.
 *
 * ```ts
 * const transactionBuilder = metaplex
 *   .nfts()
 *   .builders()
 *   .unverifyCreator({ mintAddress, creator });
 * ```
 *
 * @group Transaction Builders
 * @category Constructors
 */
const unverifyNftCreatorBuilder = (metaplex, params, options = {}) => {
  const {
    programs,
    payer = metaplex.rpc().getDefaultFeePayer()
  } = options;
  const {
    mintAddress,
    creator = metaplex.identity()
  } = params;

  // Programs.
  const tokenMetadataProgram = metaplex.programs().getTokenMetadata(programs);
  return TransactionBuilder.TransactionBuilder.make().setFeePayer(payer)

  // Verify the creator.
  .add({
    instruction: mplTokenMetadata.createRemoveCreatorVerificationInstruction({
      metadata: metaplex.nfts().pdas().metadata({
        mint: mintAddress,
        programs
      }),
      creator: creator.publicKey
    }, tokenMetadataProgram.address),
    signers: [creator],
    key: params.instructionKey ?? 'unverifyCreator'
  });
};

exports.unverifyNftCreatorBuilder = unverifyNftCreatorBuilder;
exports.unverifyNftCreatorOperation = unverifyNftCreatorOperation;
exports.unverifyNftCreatorOperationHandler = unverifyNftCreatorOperationHandler;
//# sourceMappingURL=unverifyNftCreator.cjs.map
