"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const commandBase_js_1 = require("../validation/commandBase.js");
const string_js_1 = require("../validation/string.js");
class Updater extends commandBase_js_1.CommandBase {
    className;
    consistencyLevel;
    id;
    objectsPath;
    properties;
    tenant;
    vector;
    vectors;
    constructor(client, objectsPath) {
        super(client);
        this.objectsPath = objectsPath;
    }
    withVector = (vector) => {
        this.vector = vector;
        return this;
    };
    withVectors = (vectors) => {
        this.vectors = vectors;
        return this;
    };
    withProperties = (properties) => {
        this.properties = properties;
        return this;
    };
    withId = (id) => {
        this.id = id;
        return this;
    };
    withClassName = (className) => {
        this.className = className;
        return this;
    };
    withTenant = (tenant) => {
        this.tenant = tenant;
        return this;
    };
    validateClassName = () => {
        if (!(0, string_js_1.isValidStringProperty)(this.className)) {
            this.addError('className must be set - use withClassName(className)');
        }
    };
    validateId = () => {
        if (this.id == undefined || this.id == null || this.id.length == 0) {
            this.addError('id must be set - initialize with updater(id)');
        }
    };
    withConsistencyLevel = (cl) => {
        this.consistencyLevel = cl;
        return this;
    };
    // as Record<string, any> required below because server uses swagger object as interface{} in Go to perform type switching
    // actual types are []number and [][]number but unions don't work in go-swagger
    payload = () => ({
        tenant: this.tenant,
        properties: this.properties,
        class: this.className,
        id: this.id,
        vector: this.vector,
        vectors: this.vectors,
    });
    validate = () => {
        this.validateClassName();
        this.validateId();
    };
    do = () => {
        this.validate();
        if (this.errors.length > 0) {
            return Promise.reject(new Error('invalid usage: ' + this.errors.join(', ')));
        }
        return this.objectsPath
            .buildUpdate(this.id, this.className, this.consistencyLevel)
            .then((path) => this.client.put(path, this.payload()));
    };
}
exports.default = Updater;
