'use strict';

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

var CandyMachineBuildersClient = require('./CandyMachineBuildersClient.cjs');
var CandyMachineGuardsClient = require('./CandyMachineGuardsClient.cjs');
var CandyMachinePdasClient = require('./CandyMachinePdasClient.cjs');
var callCandyGuardRoute = require('./operations/callCandyGuardRoute.cjs');
var createCandyMachine = require('./operations/createCandyMachine.cjs');
var createCandyGuard = require('./operations/createCandyGuard.cjs');
var deleteCandyMachine = require('./operations/deleteCandyMachine.cjs');
var deleteCandyGuard = require('./operations/deleteCandyGuard.cjs');
var findCandyGuardsByAuthority = require('./operations/findCandyGuardsByAuthority.cjs');
var findCandyMachineByAddress = require('./operations/findCandyMachineByAddress.cjs');
var findCandyGuardByAddress = require('./operations/findCandyGuardByAddress.cjs');
var insertCandyMachineItems = require('./operations/insertCandyMachineItems.cjs');
var mintFromCandyMachine = require('./operations/mintFromCandyMachine.cjs');
var unwrapCandyGuard = require('./operations/unwrapCandyGuard.cjs');
var updateCandyMachine = require('./operations/updateCandyMachine.cjs');
var updateCandyGuard = require('./operations/updateCandyGuard.cjs');
var wrapCandyGuard = require('./operations/wrapCandyGuard.cjs');
var PublicKey = require('../../types/PublicKey.cjs');
var CandyMachine = require('./models/CandyMachine.cjs');

/**
 * This is a client for the Candy Machine V3 module.
 *
 * It enables us to interact with the Candy Machine V3 and Candy Guard programs
 * in order to create, update, delete and mint from Candy Machines as well as
 * registering your own custom Candy Guards.
 *
 * You may access this client via the `candyMachines()` method of your `Metaplex` instance.
 *
 * ```ts
 * const candyMachineClient = metaplex.candyMachines();
 * ```
 *
 * @example
 * You can create a new Candy Machine with minimum input like so.
 * By default, the current identity of the Metaplex instance will be
 * the authority of the Candy Machine and it will immediately create
 * a Candy Guard linked to the new Candy Machine.
 *
 * ```ts
 *  const { candyMachine } = await metaplex
 *    .candyMachines()
 *    .create({
 *      itemsAvailable: toBigNumber(5000),
 *      sellerFeeBasisPoints: 333, // 3.33%
 *      collection: {
 *        address: collectionNft.address,
 *        updateAuthority: collectionUpdateAuthority,
 *      },
 *    });
 * ```
 *
 * @see {@link CandyGuard} The `CandyGuard` model
 * @group Modules
 */
class CandyMachineClient {
  constructor(metaplex) {
    this.metaplex = metaplex;
    this.guardsClient = new CandyMachineGuardsClient.CandyMachineGuardsClient(metaplex);
  }

  /**
   * You may use the `guards()` client to access the default guards
   * available as well as register your own guards.
   *
   * ```ts
   * const guardsClient = metaplex.candyMachines().guards();
   * ```
   */
  guards() {
    return this.guardsClient;
  }

  /**
   * You may use the `builders()` client to access the
   * underlying Transaction Builders of this module.
   *
   * ```ts
   * const buildersClient = metaplex.candyMachines().builders();
   * ```
   */
  builders() {
    return new CandyMachineBuildersClient.CandyMachineBuildersClient(this.metaplex);
  }

  /**
   * You may use the `pdas()` client to build PDAs related to this module.
   *
   * ```ts
   * const pdasClient = metaplex.candyMachines().pdas();
   * ```
   */
  pdas() {
    return new CandyMachinePdasClient.CandyMachinePdasClient(this.metaplex);
  }

  /** {@inheritDoc callCandyGuardRouteOperation} */
  callGuardRoute(input, options) {
    return this.metaplex.operations().execute(callCandyGuardRoute.callCandyGuardRouteOperation(input), options);
  }

  /** {@inheritDoc createCandyMachineOperation} */
  create(input, options) {
    return this.metaplex.operations().execute(createCandyMachine.createCandyMachineOperation(input), options);
  }

  /** {@inheritDoc createCandyGuardOperation} */
  createCandyGuard(input, options) {
    return this.metaplex.operations().execute(createCandyGuard.createCandyGuardOperation(input), options);
  }

  /** {@inheritDoc deleteCandyMachineOperation} */
  delete(input, options) {
    return this.metaplex.operations().execute(deleteCandyMachine.deleteCandyMachineOperation(input), options);
  }

  /** {@inheritDoc deleteCandyGuardOperation} */
  deleteCandyGuard(input, options) {
    return this.metaplex.operations().execute(deleteCandyGuard.deleteCandyGuardOperation(input), options);
  }

  /** {@inheritDoc findCandyGuardsByAuthorityOperation} */
  findAllCandyGuardsByAuthority(input, options) {
    return this.metaplex.operations().execute(findCandyGuardsByAuthority.findCandyGuardsByAuthorityOperation(input), options);
  }

  /** {@inheritDoc findCandyMachineByAddressOperation} */
  findByAddress(input, options) {
    return this.metaplex.operations().execute(findCandyMachineByAddress.findCandyMachineByAddressOperation(input), options);
  }

  /** {@inheritDoc findCandyGuardByAddressOperation} */
  findCandyGuardByAddress(input, options) {
    return this.metaplex.operations().execute(findCandyGuardByAddress.findCandyGuardByAddressOperation(input), options);
  }

  /**
   * Helper method that fetches a Candy Guard via the base
   * address used to derived its PDA.
   *
   * ```ts
   * const candyGuard = await metaplex
   *   .candyMachines()
   *   .findCandyGuardByBaseAddress({ address: base });
   * ```
   */
  findCandyGuardByBaseAddress(input, options) {
    const address = this.pdas().candyGuard({
      base: input.address
    });
    return this.findCandyGuardByAddress({
      ...input,
      address
    }, options);
  }

  /** {@inheritDoc insertCandyMachineItemsOperation} */
  insertItems(input, options) {
    return this.metaplex.operations().execute(insertCandyMachineItems.insertCandyMachineItemsOperation(input), options);
  }

  /** {@inheritDoc mintFromCandyMachineOperation} */
  mint(input, options) {
    return this.metaplex.operations().execute(mintFromCandyMachine.mintFromCandyMachineOperation(input), options);
  }

  /**
   * Helper method that refetches a given Candy Machine or Candy Guard.
   *
   * ```ts
   * const candyMachine = await metaplex.candyMachines().refresh(candyMachine);
   * const candyGuard = await metaplex.candyMachines().refresh(candyGuard);
   * ```
   */
  async refresh(model, options) {
    const input = {
      address: PublicKey.toPublicKey(model)
    };
    const refreshedModel = CandyMachine.isCandyMachine(model) ? await this.findByAddress(input, options) : await this.findCandyGuardByAddress(input, options);
    return refreshedModel;
  }

  /** {@inheritDoc unwrapCandyGuardOperation} */
  unwrapCandyGuard(input, options) {
    return this.metaplex.operations().execute(unwrapCandyGuard.unwrapCandyGuardOperation(input), options);
  }

  /** {@inheritDoc updateCandyMachineOperation} */
  update(input, options) {
    return this.metaplex.operations().execute(updateCandyMachine.updateCandyMachineOperation(input), options);
  }

  /** {@inheritDoc updateCandyGuardOperation} */
  updateCandyGuard(input, options) {
    return this.metaplex.operations().execute(updateCandyGuard.updateCandyGuardOperation(input), options);
  }

  /** {@inheritDoc wrapCandyGuardOperation} */
  wrapCandyGuard(input, options) {
    return this.metaplex.operations().execute(wrapCandyGuard.wrapCandyGuardOperation(input), options);
  }
}

exports.CandyMachineClient = CandyMachineClient;
//# sourceMappingURL=CandyMachineClient.cjs.map
