"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProfileController = void 0;
const api_1 = require("@hed-hog/api");
const api_locale_1 = require("@hed-hog/api-locale");
const common_1 = require("@nestjs/common");
const platform_express_1 = require("@nestjs/platform-express");
const change_email_dto_1 = require("./dto/change-email.dto");
const change_password_dto_1 = require("./dto/change-password.dto");
const email_verification_confirm_dto_1 = require("./dto/email-verification-confirm.dto");
const generate_webauthn_registration_options_dto_1 = require("./dto/generate-webauthn-registration-options.dto");
const regenerate_recovery_codes_dto_1 = require("./dto/regenerate-recovery-codes.dto");
const remove_email_mfa_dto_1 = require("./dto/remove-email-mfa.dto");
const remove_mfa_with_recovery_code_dto_1 = require("./dto/remove-mfa-with-recovery-code.dto");
const remove_mfa_dto_1 = require("./dto/remove-mfa.dto");
const remove_totp_mfa_dto_1 = require("./dto/remove-totp-mfa.dto");
const send_email_verification_dto_1 = require("./dto/send-email-verification.dto");
const set_preferences_dto_1 = require("./dto/set-preferences.dto");
const update_dto_1 = require("./dto/update.dto");
const verify_before_add_mfa_dto_1 = require("./dto/verify-before-add-mfa.dto");
const verify_mfa_totp_dto_1 = require("./dto/verify-mfa-totp.dto");
const verify_webauthn_registration_dto_1 = require("./dto/verify-webauthn-registration.dto");
const verify_webauthn_dto_1 = require("./dto/verify-webauthn.dto");
const profile_service_1 = require("./profile.service");
let ProfileController = class ProfileController {
    constructor(profileService) {
        this.profileService = profileService;
    }
    async updatePreferences({ id }, data, locale) {
        return this.profileService.updatePreferences(locale, id, data);
    }
    async checkMfaBeforeAdd({ id }, locale) {
        return this.profileService.checkMfaBeforeAdd(locale, id);
    }
    async checkMfaBeforeRemove({ id }, locale) {
        return this.profileService.checkMfaBeforeRemove(locale, id);
    }
    async verifyBeforeAddMfa({ id }, data, locale) {
        return this.profileService.verifyBeforeAddMfa(locale, id, data);
    }
    async generateMfaTotp({ id }, locale) {
        return this.profileService.generateMfaTotp(locale, id);
    }
    async verifyMfaTotp(locale, { id }, { token, secret, name }) {
        return this.profileService.verifyMfaTotp(locale, id, token, secret, name);
    }
    async removeMfaTotp(locale, { id }, mfaId, { token }) {
        return this.profileService.removeMfaTotp(locale, id, mfaId, token);
    }
    confirmEmailVerification({ id }, data, locale) {
        return this.profileService.confirmEmailVerification(locale, id, data);
    }
    sendEmailVerification({ id }, data, locale) {
        return this.profileService.sendEmailVerification(locale, id, data);
    }
    sendEmailVerificationMfa({ id }, data, locale) {
        return this.profileService.sendEmailVerificationMfa(locale, id, data);
    }
    sendEmailVerificationMfaConfirm({ id }, data, locale) {
        return this.profileService.confirmEmailVerificationMfa(locale, id, data);
    }
    sendCodeToRemove({ id }, locale, { email }) {
        return this.profileService.sendCodeToRemove(locale, id, email);
    }
    getEmailIdentifier({ id }) {
        return this.profileService.getEmailIdentifier(id);
    }
    async removeMfaEmail(locale, { id }, mfaId, { token, hash }) {
        return this.profileService.removeMfaEmail(locale, id, mfaId, token, hash);
    }
    getProfile({ id }) {
        return this.profileService.getProfile(id);
    }
    getMFAMethod({ id }) {
        return this.profileService.getMFAMethods(id);
    }
    updateMFA({ id: userId }, mfaId, { name }) {
        return this.profileService.updateMFA(userId, mfaId, { name });
    }
    async removeMfaWithRecoveryCode({ id }, mfaId, { recoveryCode }, locale) {
        return this.profileService.removeMfaWithRecoveryCode(locale, id, mfaId, recoveryCode);
    }
    async removeMfa({ id }, mfaId, data, locale) {
        return this.profileService.removeMfa(locale, id, mfaId, data);
    }
    async sendRecoveryCodesVerification({ id }, locale) {
        return this.profileService.sendRecoveryCodesVerification(locale, id);
    }
    async regenerateRecoveryCodes({ id }, data, locale) {
        return this.profileService.regenerateRecoveryCodes(locale, id, data);
    }
    async generateWebAuthnRegistrationOptions({ id }, { name }, locale) {
        return this.profileService.generateWebAuthnRegistrationOptions(locale, id, name);
    }
    async verifyWebAuthnRegistration({ id }, { name, attestationResponse }, locale) {
        return this.profileService.verifyWebAuthnRegistration(locale, id, name, attestationResponse);
    }
    async generateWebAuthnAuthenticationOptions({ id }, locale) {
        return this.profileService.generateWebAuthnAuthenticationOptions(locale, id);
    }
    async verifyWebAuthnAuthentication({ id }, { assertionResponse }) {
        return this.profileService.verifyWebAuthnAuthentication(id, assertionResponse);
    }
    async removeWebAuthnMfa({ id }, mfaId, locale) {
        return this.profileService.removeWebAuthnMfa(locale, id, mfaId);
    }
    changePassword({ id }, body, locale, ipAddress, userAgent) {
        return this.profileService.changePassword(locale, id, body, ipAddress, userAgent);
    }
    changeEmail({ id }, body, locale) {
        return this.profileService.changeEmail(locale, id, body);
    }
    updateAvatar(locale, { id }, file) {
        return this.profileService.updateAvatar(locale, id, file);
    }
    update(data, { id }) {
        return this.profileService.update(id, data);
    }
};
exports.ProfileController = ProfileController;
__decorate([
    (0, common_1.Put)('preferences'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, set_preferences_dto_1.SetPreferencesDto, String]),
    __metadata("design:returntype", Promise)
], ProfileController.prototype, "updatePreferences", null);
__decorate([
    (0, common_1.Post)('mfa/check-verification'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String]),
    __metadata("design:returntype", Promise)
], ProfileController.prototype, "checkMfaBeforeAdd", null);
__decorate([
    (0, common_1.Post)('mfa/check-verification-remove'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String]),
    __metadata("design:returntype", Promise)
], ProfileController.prototype, "checkMfaBeforeRemove", null);
__decorate([
    (0, common_1.Post)('mfa/verify-before-add'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, verify_before_add_mfa_dto_1.VerifyBeforeAddMfaDto, String]),
    __metadata("design:returntype", Promise)
], ProfileController.prototype, "verifyBeforeAddMfa", null);
__decorate([
    (0, common_1.Post)('totp/generate'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String]),
    __metadata("design:returntype", Promise)
], ProfileController.prototype, "generateMfaTotp", null);
__decorate([
    (0, common_1.Post)('totp/verify'),
    __param(0, (0, api_locale_1.Locale)()),
    __param(1, (0, api_1.User)()),
    __param(2, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object, verify_mfa_totp_dto_1.VerifyMfaTotpDto]),
    __metadata("design:returntype", Promise)
], ProfileController.prototype, "verifyMfaTotp", null);
__decorate([
    (0, common_1.Delete)('totp/:mfaId/remove'),
    __param(0, (0, api_locale_1.Locale)()),
    __param(1, (0, api_1.User)()),
    __param(2, (0, common_1.Param)('mfaId', common_1.ParseIntPipe)),
    __param(3, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object, Number, remove_totp_mfa_dto_1.RemoveTotpMfaDto]),
    __metadata("design:returntype", Promise)
], ProfileController.prototype, "removeMfaTotp", null);
__decorate([
    (0, common_1.Post)('email/verify/confirm'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, email_verification_confirm_dto_1.EmailVerificationDto, String]),
    __metadata("design:returntype", void 0)
], ProfileController.prototype, "confirmEmailVerification", null);
__decorate([
    (0, common_1.Post)('email/verify'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, send_email_verification_dto_1.SendEmailVerificationDto, String]),
    __metadata("design:returntype", void 0)
], ProfileController.prototype, "sendEmailVerification", null);
__decorate([
    (0, common_1.Post)('mfa/email/verify'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, send_email_verification_dto_1.SendEmailVerificationDto, String]),
    __metadata("design:returntype", void 0)
], ProfileController.prototype, "sendEmailVerificationMfa", null);
__decorate([
    (0, common_1.Post)('mfa/email/verify/confirm'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, email_verification_confirm_dto_1.EmailVerificationDto, String]),
    __metadata("design:returntype", void 0)
], ProfileController.prototype, "sendEmailVerificationMfaConfirm", null);
__decorate([
    (0, common_1.Post)('email/send-code-to-remove'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, api_locale_1.Locale)()),
    __param(2, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String, send_email_verification_dto_1.SendEmailVerificationDto]),
    __metadata("design:returntype", void 0)
], ProfileController.prototype, "sendCodeToRemove", null);
__decorate([
    (0, common_1.Get)('email'),
    __param(0, (0, api_1.User)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", void 0)
], ProfileController.prototype, "getEmailIdentifier", null);
__decorate([
    (0, common_1.Delete)('email/:mfaId/remove'),
    __param(0, (0, api_locale_1.Locale)()),
    __param(1, (0, api_1.User)()),
    __param(2, (0, common_1.Param)('mfaId', common_1.ParseIntPipe)),
    __param(3, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object, Number, remove_email_mfa_dto_1.RemoveEmailMfaDto]),
    __metadata("design:returntype", Promise)
], ProfileController.prototype, "removeMfaEmail", null);
__decorate([
    (0, common_1.Get)(),
    __param(0, (0, api_1.User)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", void 0)
], ProfileController.prototype, "getProfile", null);
__decorate([
    (0, common_1.Get)('mfa'),
    __param(0, (0, api_1.User)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", void 0)
], ProfileController.prototype, "getMFAMethod", null);
__decorate([
    (0, common_1.Put)('update-mfa/:mfaId'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, common_1.Param)('mfaId', common_1.ParseIntPipe)),
    __param(2, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Number, update_dto_1.UpdateDto]),
    __metadata("design:returntype", void 0)
], ProfileController.prototype, "updateMFA", null);
__decorate([
    (0, common_1.Delete)('mfa/:mfaId/remove-with-recovery-code'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, common_1.Param)('mfaId', common_1.ParseIntPipe)),
    __param(2, (0, common_1.Body)()),
    __param(3, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Number, remove_mfa_with_recovery_code_dto_1.RemoveMfaWithRecoveryCodeDto, String]),
    __metadata("design:returntype", Promise)
], ProfileController.prototype, "removeMfaWithRecoveryCode", null);
__decorate([
    (0, common_1.Delete)('mfa/:mfaId/remove'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, common_1.Param)('mfaId', common_1.ParseIntPipe)),
    __param(2, (0, common_1.Body)()),
    __param(3, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Number, remove_mfa_dto_1.RemoveMfaDto, String]),
    __metadata("design:returntype", Promise)
], ProfileController.prototype, "removeMfa", null);
__decorate([
    (0, common_1.Post)('recovery-codes/send-verification'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String]),
    __metadata("design:returntype", Promise)
], ProfileController.prototype, "sendRecoveryCodesVerification", null);
__decorate([
    (0, common_1.Post)('recovery-codes/regenerate'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, regenerate_recovery_codes_dto_1.RegenerateRecoveryCodesDto, String]),
    __metadata("design:returntype", Promise)
], ProfileController.prototype, "regenerateRecoveryCodes", null);
__decorate([
    (0, common_1.Post)('webauthn/generate'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, generate_webauthn_registration_options_dto_1.GenerateWebAuthnRegistrationOptionsDto, String]),
    __metadata("design:returntype", Promise)
], ProfileController.prototype, "generateWebAuthnRegistrationOptions", null);
__decorate([
    (0, common_1.Post)('webauthn/verify'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, verify_webauthn_registration_dto_1.VerifyWebAuthnRegistrationDto, String]),
    __metadata("design:returntype", Promise)
], ProfileController.prototype, "verifyWebAuthnRegistration", null);
__decorate([
    (0, common_1.Post)('webauthn/authenticate/generate'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String]),
    __metadata("design:returntype", Promise)
], ProfileController.prototype, "generateWebAuthnAuthenticationOptions", null);
__decorate([
    (0, common_1.Post)('webauthn/authenticate/verify'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, verify_webauthn_dto_1.VerifyWebAuthnDto]),
    __metadata("design:returntype", Promise)
], ProfileController.prototype, "verifyWebAuthnAuthentication", null);
__decorate([
    (0, common_1.Delete)('webauthn/:mfaId/remove'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, common_1.Param)('mfaId', common_1.ParseIntPipe)),
    __param(2, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Number, String]),
    __metadata("design:returntype", Promise)
], ProfileController.prototype, "removeWebAuthnMfa", null);
__decorate([
    (0, common_1.Put)('change-password'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, api_locale_1.Locale)()),
    __param(3, (0, common_1.Ip)()),
    __param(4, (0, common_1.Headers)('user-agent')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, change_password_dto_1.ChangePasswordDto, String, String, String]),
    __metadata("design:returntype", void 0)
], ProfileController.prototype, "changePassword", null);
__decorate([
    (0, common_1.Put)('change-email'),
    __param(0, (0, api_1.User)()),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, change_email_dto_1.ChangeEmailDto, String]),
    __metadata("design:returntype", void 0)
], ProfileController.prototype, "changeEmail", null);
__decorate([
    (0, common_1.UseInterceptors)((0, platform_express_1.FileInterceptor)('file')),
    (0, common_1.Put)('avatar'),
    __param(0, (0, api_locale_1.Locale)()),
    __param(1, (0, api_1.User)()),
    __param(2, (0, common_1.UploadedFile)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object, Object]),
    __metadata("design:returntype", void 0)
], ProfileController.prototype, "updateAvatar", null);
__decorate([
    (0, common_1.Put)(),
    __param(0, (0, common_1.Body)()),
    __param(1, (0, api_1.User)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [update_dto_1.UpdateDto, Object]),
    __metadata("design:returntype", void 0)
], ProfileController.prototype, "update", null);
exports.ProfileController = ProfileController = __decorate([
    (0, api_1.Role)(),
    (0, common_1.Controller)('profile'),
    __metadata("design:paramtypes", [profile_service_1.ProfileService])
], ProfileController);
//# sourceMappingURL=profile.controller.js.map