import { createRemoveCreatorVerificationInstruction } from '@metaplex-solarti/mpl-token-metadata';
import { useOperation } from '../../../types/Operation.mjs';
import { TransactionBuilder } from '../../../utils/TransactionBuilder.mjs';

// -----------------
// 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 = 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.make().setFeePayer(payer)

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

export { unverifyNftCreatorBuilder, unverifyNftCreatorOperation, unverifyNftCreatorOperationHandler };
//# sourceMappingURL=unverifyNftCreator.mjs.map
