import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, } from './SdkBase.js';
import { RouteBuilder } from './RouteBuilder.js';
import { SdkError } from './Errors.js';
export class RevisionsSdk extends SdkBase {
    /**
     * Lists revisions for a single file.
     *
     * @param fid The id of the file to lists revisions for.
     * @param options The list query options
     */
    async list(oid, fid, options, request = {}) {
        const { token } = request;
        const url = this.sdk.getUrl(RouteBuilder.fileRevisions(oid, fid));
        this.sdk.appendListOptions(url, options);
        const result = await this.sdk.http.get(url.toString(), { token });
        this.inspectCommonStatusCodes(result);
        const E_PREFIX = 'Unable to list revisions for a file. ';
        if (result.status !== 200) {
            this.logInvalidResponse(result);
            let e = this.createGenericSdkError(result.body);
            if (!e) {
                e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
                e.response = result.body;
            }
            throw e;
        }
        if (!result.body) {
            throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
        }
        let data;
        try {
            data = JSON.parse(result.body);
        }
        catch {
            throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
        }
        if (!Array.isArray(data.items)) {
            throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
        }
        return data;
    }
}
//# sourceMappingURL=RevisionsSdk.js.map