"use strict";
/*
 * @adonisjs/auth
 *
 * (c) Harminder Virk <virk@adonisjs.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
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.LucidUser = void 0;
const utils_1 = require("@poppinss/utils");
const standalone_1 = require("@adonisjs/core/build/standalone");
/**
 * Lucid works works a bridge between the provider and the guard
 */
let LucidUser = class LucidUser {
    constructor(user, config, hash) {
        this.user = user;
        this.config = config;
        this.hash = hash;
    }
    /**
     * Returns the value of the user id
     */
    getId() {
        return this.user ? this.user[this.config.identifierKey] : null;
    }
    /**
     * Verifies the user password
     */
    async verifyPassword(plainPassword) {
        if (!this.user) {
            throw new utils_1.Exception('Cannot "verifyPassword" for non-existing user');
        }
        /**
         * Ensure user has password
         */
        if (!this.user.password) {
            throw new utils_1.Exception('Auth user object must have a password in order to call "verifyPassword"');
        }
        const hasher = this.config.hashDriver ? this.hash.use(this.config.hashDriver) : this.hash;
        return hasher.verify(this.user.password, plainPassword);
    }
    /**
     * Returns the user remember me token or null
     */
    getRememberMeToken() {
        return this.user ? this.user.rememberMeToken || null : null;
    }
    /**
     * Updates user remember me token
     */
    setRememberMeToken(token) {
        if (!this.user) {
            throw new utils_1.Exception('Cannot set "rememberMeToken" on non-existing user');
        }
        this.user.rememberMeToken = token;
    }
};
LucidUser = __decorate([
    (0, standalone_1.inject)([null, null, 'Adonis/Core/Hash']),
    __metadata("design:paramtypes", [void 0, Object, Object])
], LucidUser);
exports.LucidUser = LucidUser;
