import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, } from './SdkBase.js';
import { RouteBuilder } from './RouteBuilder.js';
import { Exception } from '../exceptions/exception.js';
export class UsersSdk extends SdkBase {
    /**
     * Reads the current user.
     * @param request Optional request options.
     */
    async me(request = {}) {
        const { token } = request;
        const url = this.sdk.getUrl(RouteBuilder.usersMe());
        const result = await this.sdk.http.get(url.toString(), { token });
        this.inspectCommonStatusCodes(result);
        const E_PREFIX = 'Unable to read a user. ';
        if (result.status !== 200) {
            this.logInvalidResponse(result);
            throw this.createApiError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.body);
        }
        if (!result.body) {
            throw new Exception(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, { code: 'E_RESPONSE_NO_VALUE', status: result.status });
        }
        let data;
        try {
            data = JSON.parse(result.body);
        }
        catch {
            throw new Exception(`${E_PREFIX}${E_INVALID_JSON}`, { code: 'E_INVALID_JSON', status: result.status });
        }
        if (!data.key) {
            throw new Exception(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`, { code: 'E_RESPONSE_UNKNOWN', status: result.status });
        }
        return data;
    }
}
//# sourceMappingURL=UsersSdk.js.map