<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PageController; 
use App\Http\Controllers\DiamondController;
use App\Http\Controllers\Vdb_product_raw;
use App\Http\Controllers\JewelryController;
use App\Http\Controllers\RingController;
use App\Http\Controllers\CustomDesignController;
use App\Http\Controllers\VideoImportController;
use App\Http\Controllers\DiamondNewController;

use App\Http\Controllers\EmailController;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\HtmlString;
use App\Http\Controllers\SmsController;
use App\Http\Controllers\MessagingController;

/*
|--------------------------------------------------------------------------
| 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!
|
*/
use App\Http\Controllers\ProductImportController;


Route::get('/preview-test-email', [EmailController::class, 'previewTestEmail']);

Route::get('/send-test-email', [EmailController::class, 'sendTestEmail']);

Route::get('/send-daily-emails', [EmailController::class, 'sendDailyJewelryEmails']);

// Route::get('/test-email', function () {
//     $details = [
//         'title' => 'Test Email from Gems Bridge',
//         'body' => 'This is a test email sent from the Laravel application.',
//     ];

//     Mail::send('emails.test', $details, function ($message) {
//         $message->to('pinky@braintreeproducts.com')
//             ->subject('Test Email');
//     });

//     return 'Email sent successfully!';
// });
Route::post('/jewelry/create-custom-product', [JewelryController::class, 'createCustomProduct'])
    ->name('jewelry.create-custom-product');
	
Route::get('/test-email', function () {

    $details = [
        'title' => 'Test Email',
        'body' => 'This is a test email sent.',
    ];

    Mail::send('emails.test', $details, function ($message) {

        $message->to('pinky@braintreeproducts.com')
				->bcc([
                    'abhishek@braintreeproducts.com'
                ])
                ->cc(['arti@braintreeproducts.com'
                   
                ])
                
                ->subject('CC & BCC Test Email');
    });

    return 'Email sent successfully!';
});

Route::get('/send-sms', [SmsController::class, 'sendDailyJewelryMessages']);
Route::get('/num', [SmsController::class, 'phoneNoUpdate']);
Route::get('/check-mms', [MessagingController::class, 'checkIfMMSIsEnabled']);
Route::get('/send-mms', [MessagingController::class, 'sendMMS']);

Route::get('/test-smtp', function () {
    try {
        Mail::raw('This is a test email from Laravel.', function ($message) {
            $message->to('praveen.braintreeproducts@gmail.com') // change to your test email
                    ->subject('SMTP Test');
        });
        return 'mail sent successfully!';
    } catch (\Exception $e) {
        return 'Mail failed: ' . $e->getMessage();
    }
});

Route::post('/get-filter-diamond', [DiamondNewController::class, 'getFilteredDiamond']);


Route::get('/bt/jewelry', [JewelryController::class, 'index']);

Route::post('/bt/jewelry/filter', [JewelryController::class, 'jewelry_filter'])->name('jewelry.filter');

Route::get('/jewelry/{id}', [JewelryController::class, 'show']);
// Route::get('/jewelry/type/{type}', [JewelryController::class, 'showByType'])->name('jewelry-type');


Route::post('/jewelry/type', [JewelryController::class, 'showByType'])
    ->name('jewelry-type');


// Route::get('Videoupload', [VideoImportController::class, 'upload'])->name('Videoupload');
Route::get('uploadCsv', [VideoImportController::class, 'uploadCsv'])->name('uploadCsv');

Route::get('deleteVideos', [VideoImportController::class, 'deleteVideosFromCsv'])->name('deleteVideos');

Route::get('/rings', [RingController::class, 'index']);
Route::post('/rings', [RingController::class, 'store']);

Route::post('/send-email', [JewelryController::class, 'email_send'])->name('send-email');
// Route::prefix('app')->group(function () {
//     Route::post('/send-email', [JewelryController::class, 'email_send'])->name('send_email');
// });

// Define the route for importing diamonds
Route::get('/import-diamonds', [ProductImportController::class, 'importDiamonds']);
Route::get('/belgiumdia_lab', [ProductImportController::class, 'belgiumdia_lab'])->name('belgiumdia_lab');
Route::get('/diamondslabimport', [ProductImportController::class, 'diamondslab'])->name('diamondslabimport');

Route::get('/', function () {
    // dd('1111');
    return view('welcome');
})->middleware(['verify.shopify'])->name('home');


 Route::post('/create-page', [PageController::class, 'createPage'])->name('create-page');

// Route::middleware('verify.shopify')->group(function () {
//     Route::post('/create-page', [PageController::class, 'createPage'])->name('create-page');
// });

Route::get('/diamonds', [PageController::class, 'getDiamonds'])->name('diamonds.get');

Route::get('/load-more-diamond', [DiamondController::class,'load_more_data'])->name('load_more_data');
Route::get('/diamond-details', [DiamondController::class,'diamond_details'])->name('diamond_details');
Route::get('add-to-cart', [DiamondController::class,'add_to_cart'])->name('add_to_cart');
Route::get('/addToCart', [DiamondController::class,'addToCart'])->name('addToCart');
Route::get('/getAllVdbDiamonds', [Vdb_product_raw::class,'getAllVdbDiamonds'])->name('getAllVdbDiamonds');
Route::get('/demogetVdbDiamonds', [Vdb_product_raw::class,'demogetVdbDiamonds'])->name('demogetVdbDiamonds');
Route::get('/bulkGetVdbDiamonds', [Vdb_product_raw::class,'bulkGetVdbDiamonds'])->name('bulkGetVdbDiamonds');
Route::get('/add-to-wishlist', [DiamondController::class,'add_to_wishlist'])->name('add_to_wishlist');



// Route::get('/load-more-diamond', [DiamondController::class,'load_more_data'])->middleware('cors');

// Route::get('load_more_data', [YourController::class, 'load_more_data'])->middleware('cors');

Route::post('/deletepr-page', [PageController::class, 'deletePage'])->name('deletepr-page');

use App\Http\Controllers\ShopifyWebhookController;
Route::post('/shop-redact',[ShopifyWebhookController::class,'handleShopRedact'])->middleware('auth.webhook')->name('shop.redact');
// Route::post('/webhook/shop-redact', [ShopifyWebhookController::class, 'handleShopRedact']);
Route::post('/webhook/customers-redact', [ShopifyWebhookController::class, 'handleCustomersRedact']);
Route::post('/webhook/customers-data-request', [ShopifyWebhookController::class, 'handleCustomersDataRequest']);


Route::get('/log', function () {
    \Log::info('Test log message');
});

Route::get('/diamond', function () {
    return view('diamond-page');
});
Route::get('/diamond-detail', function () {
    return view('diamond-detalis');
});


Route::get('/publishProduct', [DiamondController::class,'publishProduct'])->name('publishProduct');

Route::get('/uploadDemoProduct', [DiamondController::class,'uploadDemoProduct'])->name('uploadDemoProduct');
// ------------------- custom design ----------------------------------------------------------------------
Route::post('/custom-design-store', [CustomDesignController::class, 'store'])->name('custom.design.store');


Route::get('/diamond-api', function () {
    $curl = curl_init();

	curl_setopt_array($curl, array(
		CURLOPT_URL => 'https://gate.rightclick.software/',
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_ENCODING => '',
		CURLOPT_MAXREDIRS => 10,
		CURLOPT_TIMEOUT => 0,
		CURLOPT_FOLLOWLOCATION => true,
		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		CURLOPT_CUSTOMREQUEST => 'GET',
		CURLOPT_HTTPHEADER => array(
			'serial: f6fb30',
			'apikey: pf5osdkFe54gsd5rFD524ds4327',
			'apipassword: 64fF54441fds8dsds84dFGOeoir8',
			'Content-Type: application/json',
			'Cookie: ASP.NET_SessionId=goepuyuvsb3lbe24ie0wm0tl'
		),
	));

	$response = curl_exec($curl);
	$err = curl_error($curl);
	curl_close($curl);
	if (empty($err)){
		$response = json_decode($response, true);
		$session_id = $response['SessionId'];
		//print_ex($session_id);
		//print_r($response);
	}
		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

	$curl = curl_init();

	curl_setopt_array($curl, array(
		CURLOPT_URL => 'https://gate.rightclick.software/',
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_ENCODING => '',
		CURLOPT_MAXREDIRS => 10,
		CURLOPT_TIMEOUT => 0,
		CURLOPT_FOLLOWLOCATION => true,
		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		CURLOPT_CUSTOMREQUEST => 'GET',
		CURLOPT_HTTPHEADER => array(
			'sessionid:'.$session_id,
			'api: Cert',
			'Content-Type: application/json',
			'startdate: 2000-01-01',
			'Cookie: ASP.NET_SessionId=goepuyuvsb3lbe24ie0wm0tl'
		),
	));

	$response = curl_exec($curl);
	$err = curl_error($curl);
	curl_close($curl);
	if (empty($err)){
		$response = json_decode($response, true);
      
		$records = $response['certs'];

	}
    echo "<pre>";
    print_r($response);

});