<?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('company_name', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('reg_no', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('org_no', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('legal_person', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('open_status', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('start_date', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('open_time', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('annual_date', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('reg_capital', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('ent_type', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('industry', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('district', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('authority', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('reg_addr', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('scope', 'like', '%' . $this->search['keyword'] . '%')
                ->orWhere('website', 'like', '%' . $this->search['keyword'] . '%');
        }
        return $model;
    }

}