<?php

use App\Models\audio_playlists;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\BotController;
use App\Http\Controllers\AudioBooksController;
use App\Http\Controllers\AdminController;
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| 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('/play/{id}', [AudioBooksController::class,'index']);

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/goodlib/artisan callback:run '{$data}' > /dev/null 2>&1 &");
    exit();
});

Route::get('/convert',function(){
    exec("ebook-convert '/home/torrent/books/fb2/110119.fb2' '/home/book.pdf'");
    echo 1;
});

Route::get('/getplayg',function (Request $request){
    $playlist = audio_playlists::where('identifier',$request->id)->first();
    return $playlist;
});



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

    $api = new Api($callback['data']['chat_id'],"1287759048:AAEDiTPrgKYzNKguK6y6hXwV3-tWO2cpK6I");

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