<?php

namespace Src\Modules\Auth\Infrastructure\Storage;

use Src\Common\Infrastructure\TraitStorage;
use Src\Modules\Auth\Interfaces\Infrastructure\Storage\IAdminsStorage;
use Src\Modules\Auth\Interfaces\Infrastructure\Queries\IAdminsQuery;

class AdminsStorage implements IAdminsStorage {

    use TraitStorage;

    protected IAdminsQuery $adminsQuery;

    protected int $count = 0;

    public function setAdminsQuery(IAdminsQuery $query):void
    {
        $this->adminsQuery = $query;
    }

    public function getById(string $id, array $dsl = []):array
    {
        return $this->adminsQuery->select($dsl)->whereId($id)->one();
    }

    public function getByEmail(string $email, array $dsl = []):array
    {
        return $this->adminsQuery->select($dsl)->whereEmail($email)->one();
    }

    public function getList(int $limit, int $offset, array $dsl = []):array
    {
        $this->adminsQuery->select($dsl);
        $this->count = $this->adminsQuery->getCount();
        return $this->adminsQuery->limit($limit, $offset)->all();
    }

    public function getCount(): int
    {
        return $this->count;
    }
    
}