<?php

namespace Entity\Model;

use Helpers\QueryBuilder\QueryBuilder;
use Helpers\Session\ParseBase1;

class ParamOxa extends QueryBuilder
{
    protected string $table = 'PARAMOXA with (nolock)';
    protected string $primaryKey = 'CLE';

    /**
     * find
     *
     * @param  mixed $id
     * @param  array<mixed> $selectTables
     * @param  array<mixed> $post
     * @param  mixed $option
     * @return mixed
     */
    public function find($id, array $selectTables = [], $post = [], $option = false)
    {
        if (is_string($id)) {
            $arrayTmp = $id;
        } else {
            asort($id);
            $arrayTmp = implode('_', $id);
        }

        $winCacheResult = \Helpers\Cache\Cache::surchargeGetUcache('PARAM'.(new ParseBase1())->getBroker());

        if (isset($winCacheResult[$arrayTmp])) {
            return $winCacheResult[$arrayTmp];
        } else {
            $returnReqArray = parent::find($id, $selectTables, $post, $option);
            $winCacheResult[$arrayTmp] = $returnReqArray;
            \Helpers\Cache\Cache::surchargeSetUcache('PARAM'.(new ParseBase1())->getBroker(), $winCacheResult);
            return $returnReqArray;
        }
    }
    
    /**
     * findAll
     *
     * @param  mixed $id
     * @param  array<mixed> $selectTables
     * @param  array<mixed> $post
     * @param  mixed $entity
     * @param  mixed $exact
     * @return mixed
     */
    public function findAll($id, array $selectTables = [], $post = [], $entity = null, $exact = false)
    {
        if (is_string($id)) {
            $arrayTmp = $id;
        } else {
            asort($id);
            $arrayTmp = implode('_', $id);
        }

        $winCacheResult = \Helpers\Cache\Cache::surchargeGetUcache('PARAM'.(new ParseBase1())->getBroker());

        if (isset($winCacheResult[$arrayTmp])) {
            return $winCacheResult[$arrayTmp];
        } else {
            $returnReqArray = parent::findAll($id, $selectTables, $post, $entity, $exact);
            $winCacheResult[$arrayTmp] = $returnReqArray;
            \Helpers\Cache\Cache::surchargeSetUcache('PARAM'.(new ParseBase1())->getBroker(), $winCacheResult);
            return $returnReqArray;
        }
    }

     /**
     * update
     *
     * @param  array<mixed> $valueUpdate
     * @param  mixed $id
     * @return bool
     */
    public function update(array $valueUpdate, $id) : bool
    {
        \Helpers\Cache\Cache::surchargeDeleteUcache('PARAM'.(new ParseBase1())->getBroker());
        
        return parent::update($valueUpdate, $id);
    }
}
