'use strict';

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

var mplCandyMachine = require('@metaplex-solarti/mpl-candy-machine');
var DateTime = require('../../types/DateTime.cjs');
var MetaplexError = require('../../errors/MetaplexError.cjs');

/** @group Errors */
class CandyMachineV2Error extends MetaplexError.MetaplexError {
  constructor(input) {
    super({
      ...input,
      key: `plugin.candy_machine_v2.${input.key}`,
      title: `Candy Machine V2 > ${input.title}`,
      source: 'plugin',
      sourceDetails: 'Candy Machine V2'
    });
  }
}

/** @group Errors */
class CandyMachineV2IsFullError extends CandyMachineV2Error {
  constructor(assetIndex, itemsAvailable, options) {
    super({
      options,
      key: 'candy_machine_is_full',
      title: 'Candy Machine Is Full',
      problem: `Trying to add asset number ${assetIndex.addn(1)}, but ` + `candy machine only can hold ${itemsAvailable} assets.`,
      solution: 'Limit number of assets you are adding or create a new Candy Machine that can hold more.'
    });
  }
}

/** @group Errors */
class CandyMachineV2IsEmptyError extends CandyMachineV2Error {
  constructor(itemsAvailable, options) {
    super({
      options,
      key: 'candy_machine_is_empty',
      title: 'Candy Machine Is Empty',
      problem: `You're trying to mint from an empty candy machine. ` + `All ${itemsAvailable} items have been minted.`,
      solution: 'You can no longer mint from this Candy Machine.'
    });
  }
}

/** @group Errors */
class CandyMachineV2CannotAddAmountError extends CandyMachineV2Error {
  constructor(index, amount, itemsAvailable, options) {
    super({
      options,
      key: 'candy_machine_cannot_add_amount',
      title: 'Candy Machine Cannot Add Amount',
      problem: `Trying to add ${amount} assets to candy machine that already has ${index} assets and can only hold ${itemsAvailable} assets.`,
      solution: 'Limit number of assets you are adding or create a new Candy Machine that can hold more.'
    });
  }
}

/** @group Errors */
class CandyMachineV2AddItemConstraintsViolatedError extends CandyMachineV2Error {
  constructor(index, item, options) {
    super({
      options,
      key: 'candy_machine_add_item_constraints_violated',
      title: 'Candy Machine Add Item Constraints Violated',
      problem: `Trying to add an asset with name "${item.name}" and uri: "${item.uri}" to candy machine at index ${index} that violates constraints.`,
      solution: 'Fix the name or URI of this asset and try again.'
    });
  }
}

/** @group Errors */
class CandyMachineV2NotLiveError extends CandyMachineV2Error {
  constructor(goLiveDate, options) {
    super({
      options,
      key: 'candy_machine_not_live',
      title: 'Candy Machine Not Live',
      problem: `You're trying to mint from a Candy Machine which is not live yet. ` + (goLiveDate ? `It will go live on ${DateTime.formatDateTime(goLiveDate)}.` : `Its live date has not been set yet.`),
      solution: 'You need to wait until the Candy Machine is live to mint from it. ' + 'If this is your Candy Machine, use "metaplex.candyMachinesV2().update(...)" to set the live date. ' + 'Note that the authority of the Candy Machine can mint regardless of the live date.'
    });
  }
}

/** @group Errors */
class CandyMachineV2EndedError extends CandyMachineV2Error {
  constructor(endSetting, options) {
    const endSettingType = endSetting.endSettingType === mplCandyMachine.EndSettingType.Amount ? 'Amount' : 'Date';
    const endSettingExplanation = endSetting.endSettingType === mplCandyMachine.EndSettingType.Amount ? `All ${endSetting.number} items have been minted.` : `It ended on ${DateTime.formatDateTime(endSetting.date)}.`;
    super({
      options,
      key: 'candy_machine_ended',
      title: 'Candy Machine Ended',
      problem: `The end condition [${endSettingType}] of this Candy Machine has been reached. ` + endSettingExplanation,
      solution: 'You can no longer mint from this Candy Machine.'
    });
  }
}

/** @group Errors */
class CandyMachineV2BotTaxError extends CandyMachineV2Error {
  constructor(explorerLink, cause, options) {
    super({
      options: {
        ...options,
        cause
      },
      key: 'candy_machine_bot_tax',
      title: 'Candy Machine Bot Tax',
      problem: `The NFT couldn't be fetched after being minted. ` + `This is most likely due to a bot tax that occured during minting. ` + `When someone tries to mint an NFT from a Candy Machine which cannot be minted from, ` + `the program will succeed and charge a small tax to fight against bots.`,
      solution: `Ensure you can mint from the Candy Machine. ` + `You may want to check the transaction logs for more details: [${explorerLink}].`
    });
  }
}

exports.CandyMachineV2AddItemConstraintsViolatedError = CandyMachineV2AddItemConstraintsViolatedError;
exports.CandyMachineV2BotTaxError = CandyMachineV2BotTaxError;
exports.CandyMachineV2CannotAddAmountError = CandyMachineV2CannotAddAmountError;
exports.CandyMachineV2EndedError = CandyMachineV2EndedError;
exports.CandyMachineV2Error = CandyMachineV2Error;
exports.CandyMachineV2IsEmptyError = CandyMachineV2IsEmptyError;
exports.CandyMachineV2IsFullError = CandyMachineV2IsFullError;
exports.CandyMachineV2NotLiveError = CandyMachineV2NotLiveError;
//# sourceMappingURL=errors.cjs.map
