<?php

namespace App\Services\TG\Hook\Mod;
use App\Models\Article as ModelArticle;

class SaleCode extends Base {
    
    public function setRate($aParams)
    {
        $updatedRows = ModelArticle::where('sale_code', $aParams['aOption'][1])
            ->update(['sale_rate' => $aParams['aArg'][1]]);

        return $this->toJson($updatedRows);
//        $this->oTGHttp->sendToTG(json_encode($updatedRows, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
        
//        $this->oHttp::response(200, 'ok');
        
    }
    
    public function list()
    {
        $aSaleCodeList = ModelArticle::select('sale_code', 'sale_rate')
            ->distinct()
            ->orderBy("sale_code")
            ->get()
            ->toArray();
        
        return $this->toJson($aSaleCodeList);
        
//        $this->oTGHttp->sendToTG(json_encode($aSaleCodeList, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
        
//        $this->oHttp::response(200, 'ok');
    }
    
    public function find($aParams)
    {
        
        $aSaleCodeList = ModelArticle::select('sale_code', 'sale_rate')
            ->where("sale_code", $aParams['aArg'][1])
            ->distinct()
            ->orderBy("sale_code")
            ->get()
            ->toArray();
        
        return $this->toJson($aSaleCodeList);
        
//        $this->oTGHttp->sendToTG(json_encode($aSaleCodeList, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
        
//        $this->oHttp::response(200, 'ok');
        
    }
    
}
