<?php

namespace common\logic\PointSale\UserPointSale\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\PointSale\UserPointSale\Model\UserPointSale;
use common\logic\PointSale\UserPointSale\Service\UserPointSaleDefinition;
use common\logic\User\User\Model\User;
use yii\db\ActiveQuery;

class UserPointSaleRepositoryQuery extends AbstractRepositoryQuery
{
    protected UserPointSaleDefinition $definition;

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

    public function joinPointSale(): self
    {
        $this->innerJoinWith('pointSale', true);
        return $this;
    }

    public function filterByUser(User $user): self
    {
        $this->andWhere(['user_point_sale.id_user' => $user->id]);
        return $this;
    }

    public function filterByPointSale(PointSale $pointSale): self
    {
        $this->andWhere(['id_point_sale' => $pointSale->id]);
        return $this;
    }
}