import { KeystoneReplenishStrategy } from './keystone-types.mjs';
import { POOL_ID_DEFAULT, POOL_ID_REVOKE, KEYSTONE_VERB_REVOKE } from './keystone-constants.mjs';
/**
 * Abstract Base Builder.
 * Handles configuration common to ALL strategies (Salt, Size, Replenishment, Selection).
 *
 * @template TConfig The concrete config type being built.
 */
export class KeystoneConfigBuilderBase {
    _salt = 'default';
    _size = 100;
    _replenish = 'top-up';
    _seq = 0;
    _rand = 0;
    _verbs = [];
    _targetBinding = 0; // Default 0
    /**
     * Sets the unique salt/ID for this pool.
     */
    withSalt(salt) {
        this._salt = salt;
        return this;
    }
    /**
     * Sets the total number of challenges to maintain in the pool.
     */
    withSize(size) {
        this._size = size;
        return this;
    }
    /**
    * Binds challenge selection to the content address of the target.
    * @param chars Number of hex characters to match (e.g. 4).
    */
    withTargetBinding(chars) {
        this._targetBinding = chars;
        return this;
    }
    /**
     * Configures the pool to use strictly Sequential (FIFO) selection.
     * @param count Number of challenges to consume per sign.
     */
    withFIFO(count) {
        this._seq = count;
        this._rand = 0;
        return this;
    }
    /**
     * Configures the pool to use strictly Random selection.
     * @param count Number of challenges to consume per sign.
     */
    withRandom(count) {
        this._seq = 0;
        this._rand = count;
        return this;
    }
    /**
     * Configures the pool to use Hybrid (Both FIFO and Random) selection.
     */
    withHybrid(seqCount, randCount) {
        this._seq = seqCount;
        this._rand = randCount;
        return this;
    }
    /**
     * Sets the replenishment strategy.
     */
    withReplenishStrategy(strategy) {
        this._replenish = strategy;
        return this;
    }
    /**
     * Constructs the behavioral config object.
     * Helper for subclasses.
     */
    buildBehavior() {
        return {
            size: this._size,
            replenish: this._replenish,
            selectSequentially: this._seq,
            selectRandomly: this._rand,
            targetBindingChars: this._targetBinding,
        };
    }
    /**
     * Restricts this pool to specific verbs.
     * @param verbs List of verb addresses (e.g. 'revoke^gib')
     */
    forVerbs(verbs) {
        this._verbs = verbs;
        return this;
    }
    buildBase() {
        // Helper to keep the concrete build() clean
        return {
            type: 'hash-reveal-v1', // This is overridden by concrete/interface usually, but needed for base shape
            salt: this._salt,
            allowedVerbs: this._verbs
        };
    }
}
/**
 * Concrete Builder for Hash-Reveal V1 Strategy.
 */
export class KeystoneConfigBuilder_HashV1 extends KeystoneConfigBuilderBase {
    _algo = 'SHA-256';
    _rounds = 1;
    /**
     * Sets the hashing strength.
     */
    withHash(algo, rounds = 1) {
        this._algo = algo;
        this._rounds = rounds;
        return this;
    }
    build() {
        return {
            id: this._salt, // Using salt as the unique ID for the pool config
            type: 'hash-reveal-v1',
            salt: this._salt,
            allowedVerbs: this._verbs, // <--- Mapped here
            behavior: this.buildBehavior(),
            algo: this._algo,
            rounds: this._rounds,
        };
    }
}
// ===========================================================================
// STATIC ENTRY POINT (Optional Convenience)
// ===========================================================================
export class KeystoneConfig {
    static hash() {
        return new KeystoneConfigBuilder_HashV1();
    }
}
// ===========================================================================
// FACTORY FUNCTIONS (Presets)
// ===========================================================================
export function createStandardPoolConfig(salt = POOL_ID_DEFAULT) {
    return KeystoneConfig.hash()
        .withSalt(salt)
        .withSize(100)
        .withHybrid(2, 2)
        .withReplenishStrategy('top-up')
        .build();
}
export function createRevocationPoolConfig(salt = POOL_ID_REVOKE) {
    return KeystoneConfig.hash()
        .withSalt(salt)
        .withHash('SHA-256', 10)
        .withSize(500)
        .withHybrid(10, 10)
        .withReplenishStrategy(KeystoneReplenishStrategy.scorchedEarth)
        .forVerbs([KEYSTONE_VERB_REVOKE])
        .build();
}
//# sourceMappingURL=keystone-config-builder.mjs.map