<?php 

namespace App\Services; 

use App\OwnerOutStorageRule;

Class OwnerOutStorageRuleService
{ 
    public function get(array $params, array $withs = [], $isTranslateFeature = false, array $translateColumn = [])
    {
        if ($isTranslateFeature){
            $features = app("FeatureService")->getMapArray();
            OwnerOutStorageRule::$features = $features;
            OwnerOutStorageRule::$columnMapping = $translateColumn;
        }
        $rule = OwnerOutStorageRule::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 = OwnerOutStorageRule::query();
        foreach ($params as $column=>$param){
            $query->where($column,$param);
        }
        return $query->update($values);
    }

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

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

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


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