<?php

namespace App\Classes\General\Eloquent;

use App\Classes\Exceptions\MalformedRequestException;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\QueryException;

abstract class AbstractUpdateMultipleRecord
{

    /**
     * @param Builder $query
     * @param array $ids
     * @param array $values
     * @return mixed
     * @throws MalformedRequestException
     */
    public function handler(Builder $query, array $ids, array $values){
        try{

            $record_updated = $query->whereIn('id',$ids)->update($values);

            return ($record_updated == count($ids)) ? true : false;

        } catch (QueryException|\Exception $exception){
            throw new MalformedRequestException('Unable to update the record due to unexpected error');
        }
    }



}