<?php

namespace App\Services\TG\Hook;
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]]);

        $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();
        
        $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();
        
        $this->oTGHttp->sendToTG(json_encode($aSaleCodeList, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
        
        $this->oHttp::response(200, 'ok');
        
    }
    
}
