var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import SDK from '@komi-app/sdk';
import { AddCollaboratorError, EditUserProfileRoleError, GetCollaboratorsError, GetSuperAdminPanelError, GetUserDetailsError, RemoveCollaboratorError, SignoutError, GetGoogleLoginUrlError, GetGoogleSigninUrlError, GetGoogleSignupUrlError, IsLoggedInError, GetBasicInfoError, GetGlobalRolesError, GetLegacyRolesError, PasswordAuthenticationError, GoogleOAuthActions, RefreshError } from './shared.js';
export class Auth extends SDK {
    getGoogleLoginUrl(payload) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.get('/v1/google/login-url', { queryParams: payload }).then(this.typedDataResponse(GetGoogleLoginUrlError));
        });
    }
    refresh() {
        return __awaiter(this, void 0, void 0, function* () {
            return this.post('/v1/refresh').then(this.typedVoidResponse(RefreshError));
        });
    }
    isLoggedIn() {
        return __awaiter(this, void 0, void 0, function* () {
            return this.get('/v1/users/is-logged-in').then(this.typedDataResponse(IsLoggedInError));
        });
    }
    getBasicInfo() {
        return __awaiter(this, void 0, void 0, function* () {
            return this.get('/v1/users/basic-info').then(this.typedDataResponse(GetBasicInfoError));
        });
    }
    getGlobalRoles() {
        return __awaiter(this, void 0, void 0, function* () {
            return this.get('/v1/users/global-roles').then(this.typedDataResponse(GetGlobalRolesError));
        });
    }
    signin(payload) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.post('/v1/signin', { body: payload }).then(this.typedVoidResponse(PasswordAuthenticationError));
        });
    }
    signinWithGoogle({ failureRedirectUrl, successRedirectUrl, tracking }) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.get('/v1/google/oauth', {
                queryParams: Object.assign({ action: GoogleOAuthActions.SIGNIN, failureRedirectUrl,
                    successRedirectUrl }, tracking)
            }).then(this.typedDataResponse(GetGoogleSigninUrlError));
        });
    }
    signupWithGoogle({ failureRedirectUrl, successRedirectUrl, tracking }) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.get('/v1/google/oauth', {
                queryParams: Object.assign({ action: GoogleOAuthActions.SIGNUP, failureRedirectUrl,
                    successRedirectUrl }, tracking)
            }).then(this.typedDataResponse(GetGoogleSignupUrlError));
        });
    }
    signout() {
        return __awaiter(this, void 0, void 0, function* () {
            return this.post('/v1/signout').then(this.typedVoidResponse(SignoutError));
        });
    }
    getUserDetails() {
        return __awaiter(this, void 0, void 0, function* () {
            return this.get('/v1/users/me').then(this.typedDataResponse(GetUserDetailsError));
        });
    }
    getLegacyRoles() {
        return __awaiter(this, void 0, void 0, function* () {
            return this.get('/v1/users/legacy-roles').then(this.typedDataResponse(GetLegacyRolesError));
        });
    }
    getSuperAdminPanel() {
        return __awaiter(this, void 0, void 0, function* () {
            return this.get('/v1/admins').then(this.typedDataResponse(GetSuperAdminPanelError));
        });
    }
    getProfileCollaborators() {
        return __awaiter(this, void 0, void 0, function* () {
            return this.get('/v1/collaborators').then(this.typedDataResponse(GetCollaboratorsError));
        });
    }
    addProfileCollaborator(payload) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.post('/v1/collaborators', { body: payload }).then(this.typedVoidResponse(AddCollaboratorError));
        });
    }
    removeProfileCollaborator(payload) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.put('/v1/collaborators', { body: payload }).then(this.typedVoidResponse(RemoveCollaboratorError));
        });
    }
    addUserProfileRole(payload) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.post('/v1/admins/edit-user-role', { body: payload }).then(this.typedVoidResponse(EditUserProfileRoleError));
        });
    }
    removeUserProfileRole(payload) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.put('/v1/admins/edit-user-role', { body: payload }).then(this.typedVoidResponse(EditUserProfileRoleError));
        });
    }
}
export default Auth;
