<?php

namespace App\Repositories\Company\Info\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('companyName', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('regNo', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('orgNo', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('legalPerson', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('openStatus', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('startDate', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('openTime', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('annualDate', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('regCapital', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('entType', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('industry', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('district', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('authority', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('regAddr', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('scope', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('website', 'like', '%' . $this->search['keyword'] . '%');
        }
        return $model;
    }

}