const { Model } = require('flitter-orm')
const bcrypt = require('bcrypt')

class PasswordResetModel extends Model {
    static get schema() {
        return {
            reset_on: { type: Date, default: () => new Date },
            old_hash: String,
            hash: String,
            reason: { type: String, default: 'user' }, // 'user' | 'lockout'
        }
    }

    async set_hash(password) {
        this.hash = await bcrypt.hash(password, 10)
        return this
    }

    async check(password) {
        return await bcrypt.compare(password, this.hash)
    }
}

module.exports = exports = PasswordResetModel
