<?php

namespace App\Services;

use App\OwnerPriceOperationItem;
use App\Traits\ServiceAppAop;


class OwnerPriceOperationItemService
{
    use ServiceAppAop;
    protected $modelClass=OwnerPriceOperationItem::class;
    public function get(array $params, array $withs = [], $isTranslateFeature = false, array $translateColumn = [])
    {
        if ($isTranslateFeature){
            $features = app("FeatureService")->getMapArray();
            OwnerPriceOperationItem::$features = $features;
            OwnerPriceOperationItem::$columnMapping = $translateColumn;
        }
        $rule = OwnerPriceOperationItem::query();
        if ($withs)$rule->with($withs);
        foreach ($params as $column=>$param){
            $rule->where($column,$param);
        }
        return $rule->get();
    }

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

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

    public function findUpdate(OwnerPriceOperationItem $rule, array $values)
    {
        return $rule->update($values);
    }

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

    public function insert($values)
    {
        return OwnerPriceOperationItem::query()->insert($values);
    }

    public function destroy($id)
    {
        return OwnerPriceOperationItem::destroy($id);
    }


    public function isExist(array $params)
    {
        $query = OwnerPriceOperationItem::query();
        foreach ($params as $column=>$param){
            $query->where($column,$param);
        }
        return $query->count();
    }
}
