<?php

namespace App\User\Framework\Repository;

use App\User\Framework\Entity\UserPreference;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @extends ServiceEntityRepository<UserPreference>
 */
class UserPreferenceRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, UserPreference::class);
    }

    public function findUserPreferences(int $userId): array
    {
        return $this->findBy(['userId' => $userId]);
    }

    public function findUserResolution(int $userId): ?UserPreference
    {
        return $this->findOneBy(['userId' => $userId, 'preference' => 'resolution']);
    }

    public function findUserCodec(int $userId): ?UserPreference
    {
        return $this->findOneBy(['userId' => $userId, 'preference' => 'codec']);
    }

    public function findUserLanguage(int $userId): ?UserPreference
    {
        return $this->findOneBy(['userId' => $userId, 'preference' => 'language']);
    }

    public function findUserProvider(int $userId): ?UserPreference
    {
        return $this->findOneBy(['userId' => $userId, 'preference' => 'resolution']);
    }
}
