import { SdkBase, E_RESPONSE_UNKNOWN } from './SdkBase.js';
import { RouteBuilder } from './RouteBuilder.js';
import { Kind as ProjectExecutionKind } from '../models/ProjectExecution.js';
export class ProjectExecutionSdk extends SdkBase {
    /**
     * Adds an execution logs object to the store.
     *
     * @param history The history object
     * @param organization The parent organization key
     */
    async add(organization, value, request = {}) {
        const url = this.sdk.getUrl(RouteBuilder.projectExecutions());
        url.searchParams.set('organization', organization);
        const { token } = request;
        const result = await this.sdk.http.post(url.toString(), { token, body: JSON.stringify(value) });
        this.inspectCommonStatusCodes(result);
        const E_PREFIX = 'Unable to create a project execution entity. ';
        const data = this.readResponseJSON(result, E_PREFIX);
        if (!data.key) {
            throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
        }
        return data;
    }
    /**
     * Reads an execution logs item.
     *
     * @param key The key of the history object to read.
     */
    async read(key, request = {}) {
        const url = this.sdk.getUrl(RouteBuilder.projectExecution(key));
        const { token } = request;
        const result = await this.sdk.http.get(url.toString(), { token });
        this.inspectCommonStatusCodes(result);
        const E_PREFIX = 'Unable to read a project execution entity. ';
        const data = this.readResponseJSON(result, E_PREFIX);
        if (data.kind !== ProjectExecutionKind) {
            throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
        }
        return data;
    }
    /**
     * Lists the execution logs data.
     *
     * @param key The id of the file to lists revisions for.
     * @param options The list query options
     */
    async list(options, request = {}) {
        const url = this.sdk.getUrl(RouteBuilder.projectExecutions());
        if (options.project) {
            url.searchParams.set('project', options.project);
        }
        if (options.app) {
            url.searchParams.set('app', options.app);
        }
        if (options.user) {
            url.searchParams.set('user', options.user);
        }
        // the rest query params is set through the generic function.
        const result = (await this.genericList(url, options, request));
        return result;
    }
    /**
     * Marks the data as deleted.
     *
     * @param key The key of the object to delete.
     */
    async delete(key, request = {}) {
        const url = this.sdk.getUrl(RouteBuilder.projectExecution(key));
        return this.genericDelete(url, request);
    }
    /**
     * Deletes a history in a bulk operation.
     *
     * @param keys The list of history keys to delete.
     */
    async deleteBulk(keys, request = {}) {
        const url = this.sdk.getUrl(RouteBuilder.projectExecutionBulkDelete());
        return this.genericBatchDelete(url, keys, request);
    }
    /**
     * Clears the datastore from history for a organization.
     *
     * @param organization The parent organization key
     */
    async clearOrganization(organization, request = {}) {
        const url = this.sdk.getUrl(RouteBuilder.projectExecutionClear('organization'));
        url.searchParams.set('organization', organization);
        await this.genericDelete(url, request);
    }
    /**
     * Clears all history from a project
     *
     * @param project The parent project key
     */
    async clearProject(organization, project, request = {}) {
        const url = this.sdk.getUrl(RouteBuilder.projectExecutionClear('project'));
        url.searchParams.set('organization', organization);
        url.searchParams.set('project', project);
        await this.genericDelete(url, request);
    }
    /**
     * Clears all history from a folder
     *
     * @param project The parent project key
     */
    async clearParent(organization, project, folder, request = {}) {
        const url = this.sdk.getUrl(RouteBuilder.projectExecutionClear('folder'));
        url.searchParams.set('organization', organization);
        url.searchParams.set('project', project);
        url.searchParams.set('folder', folder);
        await this.genericDelete(url, request);
    }
}
//# sourceMappingURL=ProjectExecutionsSdk.js.map