<?php

namespace domain\Producer\Producer;

use domain\_\AbstractRepositoryQuery;

class ProducerRepositoryQuery extends AbstractRepositoryQuery
{
    protected ProducerDefinition $definition;

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

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

    public function filterIsActive(): self
    {
        $this->andWhere(['producer.active' => true]);
        return $this;
    }

    public function filterIsDemoAccount(): self
    {
        $this->andWhere('name LIKE \'Démo\'');
        return $this;
    }

    public function filterHasOptionTestimony(): self
    {
        $this->andWhere('option_testimony IS NOT NULL AND option_testimony != ""');
        return $this;
    }

    public function filterHasOptionTimeSaved(): self
    {
        $this->andWhere('producer.option_time_saved > 0');
        return $this;
    }

    public function filterBySponsorshipCode(string $sponsorshipCode): self
    {
        $this->andWhere('producer.sponsorship_code LIKE :sponsorship_code')
            ->addParams(['sponsorship_code' => $sponsorshipCode]);
        return $this;
    }

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