<?php

namespace App\Services;

use App\OracleBasCustomer;

Class OracleBasCustomerService
{
    /** @var CacheService $cacheService */
    private $cacheService;
    function __construct(){
        $this->cacheService=app('CacheService');
    }
    public function getWareHouse($customerIDs = null)
    {
        if(!$customerIDs){
            return OracleBasCustomer::query()->selectRaw('Customer_Type,CustomerId,Descr_C')->where('Customer_Type','WH')->get();
        }
        return  OracleBasCustomer::query()
            ->selectRaw('Customer_Type,CustomerId,Descr_C')
            ->where('Customer_Type','WH')
            ->whereIn('CustomerId',$customerIDs)
            ->get();
    }
    public function getCustomers($codes)
    {
        return $this->cacheService->getOrExecute('OracleBasCustomersAll'.md5(json_encode($codes)),function()use($codes){
            return OracleBasCustomer::query()->select('customerid','descr_c')
                ->where('customer_type','OW')
                ->where('active_flag','Y')
                ->whereIn('customerid',$codes)
                ->get();
        },config('cache.expirations.owners'));
    }

}
