import { CommandBase } from '../validation/commandBase.js';
import { isValidStringProperty } from '../validation/string.js';
import { buildObjectsPath } from './path.js';
export default class ObjectsBatchDeleter extends CommandBase {
    className;
    consistencyLevel;
    dryRun;
    output;
    whereFilter;
    tenant;
    constructor(client) {
        super(client);
    }
    withClassName(className) {
        this.className = className;
        return this;
    }
    withWhere(whereFilter) {
        this.whereFilter = whereFilter;
        return this;
    }
    withOutput(output) {
        this.output = output;
        return this;
    }
    withDryRun(dryRun) {
        this.dryRun = dryRun;
        return this;
    }
    withConsistencyLevel = (cl) => {
        this.consistencyLevel = cl;
        return this;
    };
    withTenant(tenant) {
        this.tenant = tenant;
        return this;
    }
    payload = () => {
        return {
            match: {
                class: this.className,
                where: this.whereFilter,
            },
            output: this.output,
            dryRun: this.dryRun,
        };
    };
    validateClassName = () => {
        if (!isValidStringProperty(this.className)) {
            this.addError('string className must be set - set with .withClassName(className)');
        }
    };
    validateWhereFilter = () => {
        if (typeof this.whereFilter != 'object') {
            this.addError('object where must be set - set with .withWhere(whereFilter)');
        }
    };
    validate = () => {
        this.validateClassName();
        this.validateWhereFilter();
    };
    do = () => {
        this.validate();
        if (this.errors.length > 0) {
            return Promise.reject(new Error('invalid usage: ' + this.errors.join(', ')));
        }
        const params = new URLSearchParams();
        if (this.consistencyLevel) {
            params.set('consistency_level', this.consistencyLevel);
        }
        if (this.tenant) {
            params.set('tenant', this.tenant);
        }
        const path = buildObjectsPath(params);
        return this.client.delete(path, this.payload(), true);
    };
}
