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 SharedSdk extends SdkBase {
    /**
     * Lists shared with the user files.
     *
     * @param kinds the list of kinds to list.
     * @param options Optional query options.
     * @param request Optional request options.
     */
    async list(organization, kinds, options, request = {}) {
        const { token } = request;
        const url = this.sdk.getUrl(RouteBuilder.shared(organization));
        this.sdk.appendListOptions(url, options);
        if (Array.isArray(kinds)) {
            kinds.forEach((k) => url.searchParams.append('kind', k));
        }
        const result = await this.sdk.http.get(url.toString(), { token });
        this.inspectCommonStatusCodes(result);
        const E_PREFIX = 'Unable to list organizations. ';
        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 SdkError(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, 0);
        }
        let data;
        try {
            data = JSON.parse(result.body);
        }
        catch {
            const err = new SdkError(`${E_PREFIX}${E_INVALID_JSON}.`, 0);
            err.response = result.body;
            throw err;
        }
        if (!Array.isArray(data.items)) {
            const err = new SdkError(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`, 0);
            err.response = result.body;
            throw err;
        }
        return data;
    }
}
//# sourceMappingURL=SharedSdk.js.map