<?php
/**
 * Created by PhpStorm.
 * User: devweb
 * Date: 17/06/21
 * Time: 16:53
 */

namespace system\entity\filter\where;

class BaseWhere
{

    /**
     * @var string
     */
    protected $preSeparator = '(';

    /**
     * @var string
     */
    protected $separator = '';

    /**
     * @var string
     */
    protected $postSeparator = ')';

    /**
     * @var array
     */
    protected $parts = [];

    /**
     * baseWhere constructor.
     * @param array $args
     */
    public function __construct($args = [])
    {
        $this->addMultiple($args);
    }

    /**
     * @param array $args
     * @return $this
     */
    public function addMultiple($args = [])
    {
        foreach ((array) $args as $arg) {
            $this->parts[] = $arg;
        }

        return $this;
    }

    /**
     * @return integer
     */
    public function count()
    {
        return count($this->parts);
    }

    /**
     * @return string
     */
    public function __toString()
    {
        if ($this->count() == 1) {
            return (string) ' where '.$this->parts[0];
        }

        return ' where '.$this->preSeparator . implode($this->separator, $this->parts) . $this->postSeparator;
    }

}