<?php
/**
 * Author: lopiu
 * Date: 05.07.2020
 * Time: 23:32
 */

namespace Battles\Models;

use Battles\Database\Db;

class EffectsModel
{
    protected $DB;
    const EFFECT_HIDEUSERINFO = 5; // Обезлик

    public function __construct(int $user_id)
    {
        $this->DB = Db::getInstance()->ofetchAll('SELECT * FROM users_effects WHERE owner_id = ?', $user_id);
    }

    /**
     * Проверка обезличен ли персонаж.
     * @return int date() до конца эффекта или 0.
     */
    public function getHideUserInfoStatus(): int
    {
        if ($this->DB) {
            $i = 0;
            while ($i < count($this->DB)) {
                if ($this->DB[$i]->type == self::EFFECT_HIDEUSERINFO) {
                    return $this->DB[$i]->remaining_time;
                }
                $i++;
            }
        }
        return 0;
    }
}