<?php namespace App\Utils\Collections;

use App\DAO\Filter\QueryFilter;
use App\Services\LogService;
use App\Utils\ResponseException;

class QueryFilterCollection extends GeneralCollection
{
    public function __construct(array $query_strings=[], array $translator=[])
    {
        foreach ($query_strings as $key => $value) {
            $query = $translator[$key];
            if ($query) {
                try {
                    $this->push(QueryFilter::builder()
                        ->setNameParam($query['field'])
                        ->setTable($query['table'])
                        ->setValue($value)
                        ->setIsExact($query['is_exact'])
                        ->setComparator($query['comparator'])
                        ->build()
                    );
                } catch (ResponseException $exception) {
                    $log_service = new LogService();
                    $log_service->log_error($exception->getCode(), $exception->getMessage(), $exception->getData());
                }
            }
        }
    }
}