<?php   
namespace App\Repositories\Eloquent;   

use App\Repositories\Interfaces\BaseRepositoryInterface; 
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Model;   

class BaseRepository implements BaseRepositoryInterface 
{     
    /**      
     * @var Model      
     */     
     protected $model;       

    /**      
     * BaseRepositoryEloquent constructor.      
     *      
     * @param Model $model      
     */     
    public function __construct(Model $model)
    {         
        $this->model = $model;
    }

    /**
    * @return Collection
    */
    public function all($orderby = null, $flow = null): Collection
    {       
        return $this->model->all();
    }
    
    /**
    * @param array $attributes
    *
    * @return Model
    */
    public function create(array $attributes): Model
    {
        return $this->model->create($attributes);
    }
 
    /**
    * @param $id
    * @return Model
    */
    public function find($id): ?Model
    {
        return $this->model->findOrFail($id);
    }

    /**
    * @param array $attributes
    *
    * @return Model
    */
    public function update(array $attributes, $id): Model
    {
        $record = $this->find($id);
        $record->update($attributes);
        return $record;
    }

    /**
    * @param $id
    *
    * @return Boolean
    */
    public function delete($id)
    {
        $record = $this->find($id);
        return $record->delete($id);
    }

    /**
    * @param $column $value
    * @return Model
    */
    public function getByColumn($column, $value): ?Model
    {
        return $this->model->where($column, $value)->first();
    }
}
