<?php

namespace app\model;

use think\Model;

class AdminUser extends Model
{
    protected $name = 'admin_users';
    protected $pk = 'id';
    protected $autoWriteTimestamp = true;
    protected $createTime = 'created_at';
    protected $updateTime = false;

    const STATUS_ENABLED = 1;
    const STATUS_DISABLED = 0;

    const ROLE_ADMIN = 'admin';
    const ROLE_VIEWER = 'viewer';

    public function checkPassword($password)
    {
        return password_verify($password, $this->getAttr('password_hash') ?? '');
    }

    public static function getRoles()
    {
        return [
            self::ROLE_ADMIN => '管理员',
            self::ROLE_VIEWER => '查看员',
        ];
    }
}