import { MetaplexError } from '../../errors/MetaplexError.mjs';

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

/** @group Errors */
class UnregisteredCandyGuardError extends CandyMachineV3Error {
  constructor(name, options) {
    super({
      options,
      key: 'unregistered_candy_guard',
      title: 'Unregistered Candy Guard',
      problem: `The SDK is trying to access a custom Candy Guard named [${name}] ` + `but that guard was not registered in the SDK`,
      solution: 'Register your custom guard by calling the `metaplex.candyMachines().guards().register()` method.'
    });
  }
}

/** @group Errors */
class CandyMachineIsFullError extends CandyMachineV3Error {
  constructor(index, itemsAvailable, options) {
    super({
      options,
      key: 'candy_machine_is_full',
      title: 'Candy Machine Is Full',
      problem: `You are trying to add an item at index ${index} to a Candy Machine that ` + `can only hold a maximum of ${itemsAvailable} items.`,
      solution: 'Limit number of items you are adding or create a Candy Machine that can hold more of them.'
    });
  }
}

/** @group Errors */
class CandyMachineCannotAddAmountError extends CandyMachineV3Error {
  constructor(index, amount, itemsAvailable, options) {
    super({
      options,
      key: 'candy_machine_cannot_add_amount',
      title: 'Candy Machine Cannot Add Amount',
      problem: `You are trying to add ${amount} items to candy machine starting at index ${index} ` + ` but it can only hold a maximum of ${itemsAvailable} items.`,
      solution: 'Limit number of assets you are adding or create a Candy Machine that can hold more of them.'
    });
  }
}

/** @group Errors */
class CandyMachineItemTextTooLongError extends CandyMachineV3Error {
  constructor(index, type, text, limit, options) {
    super({
      options,
      key: 'candy_machine_item_text_too_long',
      title: 'Candy Machine Item Text Too Long',
      problem: `You are trying to add an item to a Candy Machine but its ${type} is too long. ` + `The item settings define the ${type} limit as ${limit} characters but the following ` + `content was provided [${text}] for the item at index ${index}`,
      solution: `Reduce the size of the ${type} for the item at index ${index}.`
    });
  }
}

/** @group Errors */
class CandyMachineBotTaxError extends CandyMachineV3Error {
  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}].`
    });
  }
}

/** @group Errors */
class GuardGroupRequiredError extends CandyMachineV3Error {
  constructor(availableGroups, options) {
    super({
      options,
      key: 'guard_group_required',
      title: 'Guard Group Required',
      problem: 'The provided Candy Machine defines groups of guards but no' + 'group label was provided to identity which group we should select.',
      solution: 'Please provide the label of the group you wish to select from via the `group` parameter. ' + `The available groups are [${availableGroups.join(', ')}]`
    });
  }
}

/** @group Errors */
class SelectedGuardGroupDoesNotExistError extends CandyMachineV3Error {
  constructor(selectedGroup, availableGroups, options) {
    super({
      options,
      key: 'selected_guard_group_does_not_exist',
      title: 'Selected Guard Group Does Not Exist',
      problem: `You're trying to select the guard group [${selectedGroup}] from a ` + 'Candy Machine but this group does not exists on this Candy Machine.',
      solution: availableGroups.length > 0 ? 'Please provide the label of a group that exists on the Candy Machine. ' + `The available groups are [${availableGroups.join(', ')}]` : 'There are no guard groups defined on the Candy Machine. ' + 'Please set the `group` parameter to `null` or remove it altogether.'
    });
  }
}

/** @group Errors */
class GuardMintSettingsMissingError extends CandyMachineV3Error {
  constructor(guardName, options) {
    super({
      options,
      key: 'guard_mint_settings_missing',
      title: 'Guard Mint Settings Missing',
      problem: `The Candy Machine you are trying to mint from has the [${guardName}] guard enabled. ` + 'This guard requires you to provide some additional settings when minting which you did not provide.',
      solution: `Please provide some minting settings for the [${guardName}] guard ` + `via the \`guards\` parameter like so: \`guards.${guardName} = {...}\`.`
    });
  }
}

/** @group Errors */
class GuardRouteNotSupportedError extends CandyMachineV3Error {
  constructor(guardName, options) {
    super({
      options,
      key: 'guard_route_not_supported',
      title: 'Guard Route Not Supported',
      problem: `You are trying to call the route instruction of the [${guardName}] guard ` + 'but this guard does not support this feature or did not register it on the SDK.',
      solution: 'Please select a guard that support the route instruction feature. ' + 'If you are using a custom guard, make sure you registered the route instruction ' + 'feature by implementing the `routeSettingsParser` method on the guard manifest.'
    });
  }
}

/** @group Errors */
class CandyGuardRequiredOnCandyMachineError extends CandyMachineV3Error {
  constructor(options) {
    super({
      options,
      key: 'candy_guard_required_on_candy_machine',
      title: 'Candy Guard Required On Candy Machine',
      problem: `The provided Candy Machine does not have a Candy Guard associated with ` + `it yet, it is required for the operation you are trying to execute.`,
      solution: 'Please provide a Candy Machine with an associated Candy Guard account.'
    });
  }
}

/** @group Errors */
class GuardNotEnabledError extends CandyMachineV3Error {
  constructor(guard, group, options) {
    super({
      options,
      key: 'guard_not_enabled',
      title: 'Guard Not Enabled',
      problem: group ? `The guard [${guard}] is not enabled on the group [${group}] of the Candy Machine.` : `The guard [${guard}] is not enabled on the Candy Machine.`,
      solution: 'Please provide a different guard or select a different group ' + 'such that the provided guard is enabled on the selected group.'
    });
  }
}

export { CandyGuardRequiredOnCandyMachineError, CandyMachineBotTaxError, CandyMachineCannotAddAmountError, CandyMachineIsFullError, CandyMachineItemTextTooLongError, CandyMachineV3Error, GuardGroupRequiredError, GuardMintSettingsMissingError, GuardNotEnabledError, GuardRouteNotSupportedError, SelectedGuardGroupDoesNotExistError, UnregisteredCandyGuardError };
//# sourceMappingURL=errors.mjs.map
