<?php

namespace AuthStack\UserDirectory\Model;

use Illuminate\Database\Eloquent\Model;

class AccountStatus extends Model
{
    const S_ACTIVE = 1;
    const S_PENDING = 2;
    const S_RESETTING_PASSWORD = 3;
    const S_PASSWORD_EXPIRED = 4;
    const S_DEACTIVATED = 5;
    const S_SUSPENDED = 6;
    const S_LOCKED_OUT = 7;

    const S_MESSAGES = [
        self::S_PENDING => 'Account is pending activation',
        self::S_RESETTING_PASSWORD => 'Account password is being reset',
        self::S_PASSWORD_EXPIRED => 'Account password has expired, please update the password first',
        self::S_DEACTIVATED => 'Account is deactivated',
        self::S_SUSPENDED => 'Account is suspended',
        self::S_LOCKED_OUT => 'Account is locked out due to too many failed authentication attempts'
    ];

    protected $table = 'accounts_statuses';
    public $timestamps = true;

    public static function isActive(int $status)
    {
        return $status === static::S_ACTIVE;
    }

    public static function getMessage(int $status): string
    {
        return self::S_MESSAGES[$status] ?? 'Unable to determine account status';
    }
}