<?php

namespace App\Services;

use App\Services\common\BatchUpdateService;
use App\StoreCheckingReceiveItem;
use App\Traits\ServiceAppAop;


class StoreCheckingReceiveItemService
{
    use ServiceAppAop;
    protected $modelClass=StoreCheckingReceiveItem::class;


    public function updateFind(StoreCheckingReceiveItem $item, array $values){
        $item->update($values);
        $item->load(['commodity'=>function($query){
            $query->with('barcodes');
        }]);
        return $item;
    }

    public function find($id){
        return StoreCheckingReceiveItem::query()->find($id);
    }

    public function create(array $params){
        return StoreCheckingReceiveItem::query()->create($params);
    }

    public function update(array $params, array $values){
        $query = StoreCheckingReceiveItem::query();
        foreach ($params as $column => $param){
            if (is_array($param))$query->whereIn($column,$param);
            else $query->where($column,$param);
        }
        return $query->update($values);
    }

    public function batchUpdate(array $params){
        return app(BatchUpdateService::class)->batchUpdate('store_checking_receive_items', $params);
    }

    public function destroy($id){
        return StoreCheckingReceiveItem::destroy($id);
    }
    public function batchUpdateItself($column, array $params)
    {
        return app(BatchUpdateService::class)->batchUpdateItself('store_checking_receive_items', $column, $params);
    }

}
