'use strict';

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

var buffer = require('buffer');
var mplTokenMetadata = require('@metaplex-solarti/mpl-token-metadata');
var common = require('../../utils/common.cjs');
var GpaBuilder = require('../../utils/GpaBuilder.cjs');
var BigNumber = require('../../types/BigNumber.cjs');

const MAX_NAME_LENGTH = 32;
const MAX_SYMBOL_LENGTH = 10;
const MAX_URI_LENGTH = 200;
const MAX_CREATOR_LEN = 32 + 1 + 1;
const DATA_START = 1 + 32 + 32;
const NAME_START = DATA_START + 4;
const SYMBOL_START = NAME_START + MAX_NAME_LENGTH + 4;
const URI_START = SYMBOL_START + MAX_SYMBOL_LENGTH + 4;
const CREATORS_START = URI_START + MAX_URI_LENGTH + 2 + 1 + 4;
class TokenMetadataGpaBuilder extends GpaBuilder.GpaBuilder {
  constructor(metaplex, programId) {
    super(metaplex, programId ?? mplTokenMetadata.PROGRAM_ID);
  }
  whereKey(key) {
    return this.where(0, BigNumber.toBigNumber(key, 'le'));
  }
}
class MetadataV1GpaBuilder extends TokenMetadataGpaBuilder {
  constructor(metaplex, programId) {
    super(metaplex, programId);
    this.whereKey(mplTokenMetadata.Key.MetadataV1);
  }
  selectUpdatedAuthority() {
    return this.slice(1, 32);
  }
  whereUpdateAuthority(updateAuthority) {
    return this.where(1, updateAuthority);
  }
  selectMint() {
    return this.slice(33, 32);
  }
  whereMint(mint) {
    return this.where(33, mint);
  }
  selectName() {
    return this.slice(NAME_START, MAX_NAME_LENGTH);
  }
  whereName(name) {
    return this.where(NAME_START, buffer.Buffer.from(common.padEmptyChars(name, MAX_NAME_LENGTH)));
  }
  selectSymbol() {
    return this.slice(SYMBOL_START, MAX_SYMBOL_LENGTH);
  }
  whereSymbol(symbol) {
    return this.where(SYMBOL_START, buffer.Buffer.from(common.padEmptyChars(symbol, MAX_SYMBOL_LENGTH)));
  }
  selectUri() {
    return this.slice(URI_START, MAX_URI_LENGTH);
  }
  whereUri(uri) {
    return this.where(URI_START, buffer.Buffer.from(common.padEmptyChars(uri, MAX_URI_LENGTH)));
  }
  selectCreator(position) {
    return this.slice(CREATORS_START + (position - 1) * MAX_CREATOR_LEN, CREATORS_START + position * MAX_CREATOR_LEN);
  }
  whereCreator(position, creator) {
    return this.where(CREATORS_START + (position - 1) * MAX_CREATOR_LEN, creator);
  }
  selectFirstCreator() {
    return this.selectCreator(1);
  }
  whereFirstCreator(firstCreator) {
    return this.whereCreator(1, firstCreator);
  }
}

exports.MetadataV1GpaBuilder = MetadataV1GpaBuilder;
exports.TokenMetadataGpaBuilder = TokenMetadataGpaBuilder;
//# sourceMappingURL=gpaBuilders.cjs.map
