<?php

namespace common\logic\User\User\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\Producer\Producer\Model\Producer;
use common\logic\User\User\Model\User;
use common\logic\User\User\Service\UserDefinition;

class UserRepositoryQuery extends AbstractRepositoryQuery
{
    protected UserDefinition $definition;

    public function loadDependencies(): void
    {
        $this->loadDefinition(UserDefinition::class);
    }

    public function filterByPasswordResetToken(string $token): self
    {
        $this->andWhere(['password_reset_token' => $token]);
        return $this;
    }

    public function filterByEmail(string $email): self
    {
        $this->andWhere(['email' => $email]);
        return $this;
    }

    public function filterByUsername(string $username): self
    {
        $this->andWhere(['username' => $username]);
        return $this;
    }

    public function filterByProducer(Producer $producer): self
    {
        $this->andWhere(['user.id_producer' => $producer->id]);
        return $this;
    }

    public function filterByStatus(string $status): self
    {
        $this->andWhere(['user.status' => $status]);
        return $this;
    }

    public function isStatusProducer(): self
    {
        return $this->filterByStatus(User::STATUS_PRODUCER);
    }
}