"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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NestAuthAdminUser = void 0;
const typeorm_1 = require("typeorm");
const argon2_1 = require("@node-rs/argon2");
let NestAuthAdminUser = class NestAuthAdminUser extends typeorm_1.BaseEntity {
    id;
    email;
    name;
    passwordHash;
    metadata;
    lastLoginAt;
    createdAt;
    updatedAt;
    normalizeEmail() {
        if (this.email) {
            this.email = this.email.toLowerCase();
        }
    }
    normalizeEmailOnUpdate() {
        if (this.email) {
            this.email = this.email.toLowerCase();
        }
    }
    async setPassword(password) {
        this.passwordHash = await (0, argon2_1.hash)(password, {
            algorithm: 2,
            memoryCost: 65536,
            timeCost: 3,
            parallelism: 4,
        });
    }
    async validatePassword(password) {
        if (!this.passwordHash) {
            return false;
        }
        try {
            return await (0, argon2_1.verify)(this.passwordHash, password);
        }
        catch {
            return false;
        }
    }
};
exports.NestAuthAdminUser = NestAuthAdminUser;
__decorate([
    (0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
    __metadata("design:type", String)
], NestAuthAdminUser.prototype, "id", void 0);
__decorate([
    (0, typeorm_1.Column)({ unique: true }),
    (0, typeorm_1.Index)(),
    __metadata("design:type", String)
], NestAuthAdminUser.prototype, "email", void 0);
__decorate([
    (0, typeorm_1.Column)({ nullable: true }),
    __metadata("design:type", String)
], NestAuthAdminUser.prototype, "name", void 0);
__decorate([
    (0, typeorm_1.Column)(),
    __metadata("design:type", String)
], NestAuthAdminUser.prototype, "passwordHash", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'simple-json', nullable: true, default: '{}' }),
    __metadata("design:type", Object)
], NestAuthAdminUser.prototype, "metadata", void 0);
__decorate([
    (0, typeorm_1.Column)({ nullable: true }),
    __metadata("design:type", Date)
], NestAuthAdminUser.prototype, "lastLoginAt", void 0);
__decorate([
    (0, typeorm_1.CreateDateColumn)(),
    __metadata("design:type", Date)
], NestAuthAdminUser.prototype, "createdAt", void 0);
__decorate([
    (0, typeorm_1.UpdateDateColumn)(),
    __metadata("design:type", Date)
], NestAuthAdminUser.prototype, "updatedAt", void 0);
__decorate([
    (0, typeorm_1.BeforeInsert)(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], NestAuthAdminUser.prototype, "normalizeEmail", null);
__decorate([
    (0, typeorm_1.BeforeUpdate)(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], NestAuthAdminUser.prototype, "normalizeEmailOnUpdate", null);
exports.NestAuthAdminUser = NestAuthAdminUser = __decorate([
    (0, typeorm_1.Entity)('nest_auth_admin_users')
], NestAuthAdminUser);
//# sourceMappingURL=admin-user.entity.js.map