<?php
/*ini_set('display_errors', 1); 
ini_set('display_startup_errors', 1); 
error_reporting(E_ALL);*/
require 'vendor/autoload.php'; // Assuming you've installed the DeepSeek PHP client

use DeepSeek\DeepSeekClient;


ini_set('max_execution_time', 1200);

// Initialize the client with your API key
//$client = new DeepSeekClient('sk-efead9fab1c746ba8cc194ef36449477');
$client = DeepSeekClient::build(apiKey:'sk-efead9fab1c746ba8cc194ef36449477',timeout:60);
// Path to your receipt image
//$imagePath = 'path/to/your/receipt.jpg';
if(isset($_GET['file_url'])){
    if($_GET['file_url'] == ""){
        echo "No file_url";exit;
    }
}
$filetext = file_get_contents($_GET['file_url']);

try {
    // Upload the image and ask if it's a valid receipt
    $response = $client->query(
                     "Please analyze this JSON from google vision api and check this receipt is it valid and not modified by checking the price, and total is it reasonable for that product, and any other suspicious value.
                     Ignore the Tax Service Charges, and discount.  If found suspicious amount with high percentage more than 80%, please return false for the result,because some people trying to modify the receipt. Note that this is OCR data, which it may have OCR reading wrong value when the image is blur. The incorrect total allowed mistake for 50% difference. Beside this, if the receipt have (Voucher,Coupon,Redemption,Prepaid,Top-up,Reload), not in t&c but in the price listing, return 'isvalid' equal false, and 'special' equal true.  
                    ".'The response should only return in this json format : { "isvalid":"true","special":"false","reason":"The reason of validation" }depends on the validation result without any other text. The google vision JSON:'.$filetext
                    
    )->run();
    
    // Process the response
    //echo "Receipt Validation Result:\n";
    //var_dump($response);
    $result = json_decode($response);
    if($result == false || $result->choices == NULL){
        var_dump($response);exit;
    }
    $finalResult =  $result->choices[0]->message->content;
    $finalResult = str_replace("```json","",$finalResult);
    $finalResult = str_replace("```","",$finalResult);
    echo $finalResult;
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}
?>