<?php

namespace App\Repositories\Call\Records\Criteria;

use App\Repositories\Base\Criteria;
use App\Repositories\Contracts\RepositoryInterface as Repository;

class MultiWhere extends Criteria
{

    private $search = [];

    /**
     * MultiWhere constructor.
     * @param array $search
     *
     */
    public function __construct(array $search)
    {
        $this->search = $search;
    }

    /**
     * @param $model
     * @param RepositoryInterface $repository
     * @return mixed
     */
    public function apply($model, Repository $repository)
    {
        if (isset($this->search['keyword']) && $this->search['keyword']) {
            $model = $model->where('id', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('phone', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('start_time', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('end_time', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('record_path', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('hangup_dispostion', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('ip', 'like', '%' . $this->search['keyword'] . '%');
        }
        return $model;
    }

}