<?php

namespace App\Classes\General\Eloquent;

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

abstract class AbstractDeleteMultipleRecord
{

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

            $record_deleted = $query->whereIn('id',$ids)->delete();

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

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



}