<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\BotController;
use App\Http\Controllers\AudioBooksController;
use App\Http\Controllers\AdminController;
use Illuminate\Http\Request;
use App\TelegramBot\Api;


/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/get_chart',[AdminController::class,'get_chart']);
Route::get('/ar_chart',[AdminController::class,'ar_chart']);
Route::get('/get_stats',[AdminController::class,'get_stats']);

Route::post('/callback', function (){
    $data = file_get_contents('php://input');
    $data = str_replace("'","",$data);
    exec("php /var/www/html/knigavsluh/artisan callback:run '{$data}' > /dev/null 2>&1 &");
    exit();
});

Route::post('/api_books_callback',function (Request $request){
    $data = $request->data;
    $callback = json_decode($data,true);

    $api = new Api($callback['data']['chat_id'],"1634226596:AAGS5cBHczuhOdJEkPpq7WgKKwhGl4aUK_8");

    $api->execute("sendDocument",[
        "document" => $callback['book'][$callback['data']['type']],
        'caption' => '[@Knigavsluh_bot](t.me/Knigavsluh_bot?start=share)'
    ]);
});

