<?php


namespace App\Services;


use App\StationTaskBatch;
use App\StationTaskChild;
use Illuminate\Support\Facades\Cache;

class StationTaskChildService
{

    function get(array $kvPairs){
        ksort($kvPairs);
        return Cache::remember('stationTaskChild_'.md5(json_encode($kvPairs)), config('cache.expirations.oftenChange'), function ()use($kvPairs) {
            $query = StationTaskChild::query();
            foreach ($kvPairs as $column => $value){
                if (is_array($value))$query->whereIn($column,$value);
                else $query->where($column,$value);
            }
            return $query->get();
        });
    }
    public function insert(array $stationMissionBatches): bool
    {
        $inserted = StationTaskChild::query()->insert($stationMissionBatches);
        LogService::log(__METHOD__,__FUNCTION__,json_encode($stationMissionBatches).
            '||'.json_encode(array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS),0,3)));
        return $inserted;
    }
}
