"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const commandBase_js_1 = require("../validation/commandBase.js");
class GetterById extends commandBase_js_1.CommandBase {
    additional;
    className;
    id;
    consistencyLevel;
    nodeName;
    tenant;
    objectsPath;
    constructor(client, objectsPath) {
        super(client);
        this.objectsPath = objectsPath;
        this.additional = [];
    }
    withId = (id) => {
        this.id = id;
        return this;
    };
    withClassName = (className) => {
        this.className = className;
        return this;
    };
    withTenant = (tenant) => {
        this.tenant = tenant;
        return this;
    };
    extendAdditional = (prop) => {
        this.additional = [...this.additional, prop];
        return this;
    };
    withAdditional = (additionalFlag) => this.extendAdditional(additionalFlag);
    withVector = () => this.extendAdditional('vector');
    withConsistencyLevel = (cl) => {
        this.consistencyLevel = cl;
        return this;
    };
    withNodeName = (nodeName) => {
        this.nodeName = nodeName;
        return this;
    };
    validateId = () => {
        if (this.id == undefined || this.id == null || this.id.length == 0) {
            this.addError('id must be set - initialize with getterById(id)');
        }
    };
    validate = () => {
        this.validateId();
    };
    buildPath = () => {
        return this.objectsPath.buildGetOne(this.id, this.className, this.additional, this.consistencyLevel, this.nodeName, this.tenant);
    };
    do = () => {
        this.validate();
        if (this.errors.length > 0) {
            return Promise.reject(new Error('invalid usage: ' + this.errors.join(', ')));
        }
        return this.buildPath().then((path) => {
            return this.client.get(path);
        });
    };
}
exports.default = GetterById;
