<?php


namespace App\Http\Controllers;


use App\Console\Commands\ChannelManager\BestAvailableRateSyncService;
use App\Core\Mail\BookingCancellationRequestMail;
use App\Core\Mail\BookingInvoiceUpdateMail;
use App\Core\Mail\BookingPaymentDataCodeMail;
use App\Core\Mail\BookingPropertyAddonUpdateMail;
use App\Core\Mail\BookingTicketMail;
use App\Core\Mail\CancelBookingMail;
use App\Core\Mail\ContactFormMail;
use App\Core\Mail\DailyReportMail;
use App\Core\Mail\DailyReportMailSales;
use App\Core\Mail\InventoryActionMail;
use App\Core\Mail\LogMail;
use App\Core\Mail\ModifiedBookingMail;
use App\Core\Mail\NewBookingMail;
use App\Core\Mail\PropertyProductOfferMail;
use App\Core\Mail\TrialFirstMail;
use App\Core\Mail\TrialSecondMail;
use App\Core\Service\ManualPaymentMailService;
use App\Core\Service\NewBookingMailService;
use App\Core\Service\NotificationService;
use App\Core\Service\PropertyPaymentService;
use App\Core\Service\PropertyRoomAvailabilityService;
use App\Core\Validator\ExampleValidator;
use App\Models\PropertyCancellationPolicy;
use App\Models\PropertyPricingPolicyAdult;
use App\Models\PropertyRoomRateChannelMapping;
use App\Models\PropertyRoomRatePrice;
use App\Models\vwBookingSummary;
use App\Notifications\DirectPushNotificationUser;
use App\Notifications\PushNotificationPropertyUser;
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
use Illuminate\Http\Request;
use Illuminate\Mail\Mailer;
use Illuminate\Support\Carbon;

use Illuminate\Support\Facades\App;

use App\Core\Repository\PropertyFactAttribute\PropertyFactAttributeRepository;
use App\Core\Repository\PropertyUnit\PropertyUnitRepository;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
use Mews\Pos\Pos;
use Exception;


class TestController extends Controller
{
    private $exampleValidator;
    private $propertyFactAttributeRepository;
    private $propertyUnitRepository;


    public function __construct(
        ExampleValidator $exampleValidator,
        PropertyFactAttributeRepository $propertyFactAttributeRepository,
        PropertyUnitRepository $propertyUnitRepository,
        PropertyPaymentService $propertyPaymentService,
        NewBookingMailService $newBookingMailService,
        Mailer $mailer,
        NotificationService $notificationService,
        PropertyRoomAvailabilityService $propertyRoomAvailabilityService,
        ManualPaymentMailService $manualPaymentMailService
    )
    {
        $this->exampleValidator = $exampleValidator;
        $this->propertyFactAttributeRepository = $propertyFactAttributeRepository;
        $this->propertyUnitRepository = $propertyUnitRepository;

        $this->propertyPaymentService = $propertyPaymentService;
        $this->newBookingMailService = $newBookingMailService;
        $this->mailer = $mailer;

        $this->notificationService = $notificationService;
        $this->propertyRoomAvailabilityService = $propertyRoomAvailabilityService;

        $this->manualPaymentMailService = $manualPaymentMailService;
    }


    public function testResponse(Request $request)
    {

        $inputAll = $request->input();

        dd($inputAll);

        Log::debug(json_encode($inputAll));

        $response = [
            'success' => true
        ];

        return response()->json($response);

        dd($inputAll);


        $publishableKey = 'pk_test_51HuYHvEa9cmPdLq3cIxkIJ2y6EtTL1mSuPKKbtSJuMemCaLW49h8lPhVINB0ju8MvYDwM45cxk1oFpz8EoMpVpum00Rw3qKohb';
        $secretKey = 'sk_test_51HuYHvEa9cmPdLq3ANG7ZYaGB9zMuhQZlwH19axJRauZsMnnpnuGBN1h8iAfr9kNVWe4FWcEcvZiMjn3hhBELHHx00hiBgjO41';

        try {

            //Secret key
            $stripe = new \Stripe\StripeClient($secretKey);


            $charge = $stripe->charges->create([
                'currency' => 'EUR',
                'amount' => 120,//10.20
                'source' => $inputAll['source']
            ]);

            dd($inputAll, $charge);

            if ($charge['status'] == 'succeeded') {

            }

        } catch (\Exception $e) {
            dd($e->getMessage());
        }

        dd($inputAll);


        $account = [
            'bank' => 'akbank',
            'model' => '3d_pay',
            'client_id' => '100200000',
            'store_key' => '123456',
            'env' => 'test', // test veya production. test ise; API Test Url, production ise; API Production URL kullanılır.
        ];


        $pos = new \App\Core\Payment\Pos\Pos($account);

        $orderParams = Cache::get($request->input('oid'));


        $pos->prepare($orderParams);
        $payment = $pos->payment();

        dd($payment, $payment->response, $payment->response->status, $payment->response->code);

        $response = $payment->response;

        dd($response, $request->input());


    }

    public function test(Request $request)
    {

        $inputAll = $request->input();


        try {


            /*$path = resource_path('data/data.json');
            $json = file_get_contents($path);
            $summaryReportData = json_decode($json, true);

            $this->mailer->onQueue('dailyReportMail', new DailyReportMail($summaryReportData));

            die();*/

            //$mailParams = ['booking_id' => 72027];
            //$this->newBookingMailService->process($mailParams);

            die();

            $initializePaymentParam = [
                'propertyId' => 1,
                'orderId' => getCodeGenerate(),
                'installment' => 0,
                'amount' => (double)1.25,
                'currency' => 'AZN',
                'responseUrl' => 'http://api.extranetwork.local/testResponse',
                'preferredPaymentTypeId' => 606,
                'ipAddress' => $request->getClientIp(),
                /*'creditCard' => [
                    'name' => 'Test Card',
                    'number' => '4000007546012078',
                    'month' => '04',
                    'year' => '2028',
                    'cvv' => '236',
                ]*/
            ];

            //dd($initializePaymentParam);

            //4938460158754205 2024/11 715 123456
            //4119790155203496 2024/04 579

            $initializePayment = $this->propertyPaymentService->initializePayment($initializePaymentParam);

            dd($initializePayment);

            die();

            $param = [
                'property_id' => 1805,
                'subject' => '🛎️ ' . __('notification-new_booking', [], 'en'),
                'message' => __('notification-new_booking_desc', ['hotel_name' => 'Seres Hotel', 'amount' => 198.45, 'currency' => 'EUR'], 'en'),
            ];

            Notification::route('OneSignal', null)->notify(new PushNotificationPropertyUser($param));

            die();

            $mailParams = ['booking_id' => 71740];
            $this->newBookingMailService->process($mailParams);


            $propertyProductOfferMail = [
                'offerKey' => '6c0d6ee7-c378-4859-9603-7967ede0e120'
            ];

            $this->mailer->onQueue('propertyProductOfferMail', new PropertyProductOfferMail($propertyProductOfferMail));


            //


            //$newBookingNotificationParam = ['booking_id' => 63012];
            //$this->notificationService->sendNewBookingNotification($newBookingNotificationParam);
            //PUSH NOTIFICATION

            die();


            /*$report = json_decode('{"name":"Cemile Ays\u0131n ARIKAN","email":"cemile@extranetwork.com","daily":{"data":{"1258":{"id":1258,"name":"Rayelin Hotel Istanbul Old City","count":3,"total":1504.2399999999998,"commission":225.63599999999997},"580":{"id":580,"name":"\u00d6zkaymak Falez Hotel","count":1,"total":1054.7,"commission":158.205},"1007":{"id":1007,"name":"T\u00fcrkay Hotel","count":1,"total":226.59912,"commission":27.191894400000002}},"title":"Daily Report","type":"daily","period":"20.01.2025","summary":{"count":5,"total":2785.5391199999995,"commission":411.03289440000003}},"monthly":{"data":{"1258":{"id":1258,"name":"Rayelin Hotel Istanbul Old City","count":13,"total":8061.37,"commission":1209.2054999999998},"580":{"id":580,"name":"\u00d6zkaymak Falez Hotel","count":6,"total":3558.55,"commission":533.7825},"1007":{"id":1007,"name":"T\u00fcrkay Hotel","count":3,"total":1301.88312,"commission":156.2259744},"1205":{"id":1205,"name":"Duck Otel","count":7,"total":386.2046399999999,"commission":57.93069599999999}},"title":"Monthly Report","type":"monthly","period":"01.2025","summary":{"count":29,"total":13308.00776,"commission":1957.1446703999998}},"annually":{"data":{"1258":{"id":1258,"name":"Rayelin Hotel Istanbul Old City","count":13,"total":8061.37,"commission":1209.2054999999998},"580":{"id":580,"name":"\u00d6zkaymak Falez Hotel","count":6,"total":3558.55,"commission":533.7825},"1007":{"id":1007,"name":"T\u00fcrkay Hotel","count":3,"total":1301.88312,"commission":156.2259744},"1205":{"id":1205,"name":"Duck Otel","count":7,"total":386.2046399999999,"commission":57.93069599999999}},"title":"Annually Report","type":"annually","period":"2025","summary":{"count":29,"total":13308.00776,"commission":1957.1446703999998}},"activeProperty":[{"id":1258,"name":"Rayelin Hotel Istanbul Old City","commission":15,"year":"2024","month":"2024-12","contract_user_id":22},{"id":1205,"name":"Duck Otel","commission":15,"year":"2024","month":"2024-08","contract_user_id":22},{"id":1007,"name":"T\u00fcrkay Hotel","commission":12,"year":"2024","month":"2024-02","contract_user_id":22},{"id":580,"name":"\u00d6zkaymak Falez Hotel","commission":15,"year":"2022","month":"2022-11","contract_user_id":22}]}',1);
            $this->mailer->onQueue('dailyReportSalesMail', new DailyReportMailSales($report));

            die();*/


        } catch (Exception $e) {
            dd($e->getMessage());
            Log::debug($e->getMessage());
        }


        die();

        //$summaryReportData = json_decode('{"daily":{"data":{"EUR":{"count":9,"total":2080.9900000000002,"commission":240.5208},"GEL":{"count":4,"total":958.6600000000001,"commission":24.5828},"TRY":{"count":1,"total":27000,"commission":4050}},"title":"Daily Report","period":"11.12.2024","summary":{"count":14,"total":3140.391492,"commission":359.35053736000003}},"monthly":{"data":{"EUR":{"count":98,"total":32560.43,"commission":3690.2600999999995},"GEL":{"count":81,"total":39810.82000000001,"commission":1132.786},"TRY":{"count":24,"total":151606.96,"commission":21772.044}},"title":"Monthly Report","period":"12.2024","summary":{"count":203,"total":50083.697692,"commission":4665.479554399999},"summaryCheckoutData":{"EUR":{"count":202,"total":59142.93000000001,"commission":5871.0608},"GEL":{"count":101,"total":41661.039999999986,"commission":1358.6717999999996},"TRY":{"count":31,"total":257321.56,"commission":38041.734000000004},"USD":{"count":2,"total":120,"commission":14.4}},"summaryCheckout":{"count":336,"total":80288.454236,"commission":7380.090077360001}},"annually":{"data":{"EUR":{"count":3711,"total":1805925.850000003,"commission":197665.67849999937},"GEL":{"count":1841,"total":1037083.2200000021,"commission":30233.390399999997},"TRY":{"count":335,"total":2973705.5399999996,"commission":387296.1086999998},"USD":{"count":37,"total":5649.07,"commission":677.8884000000002},"GBP":{"count":20,"total":18908.2,"commission":2268.9840000000004}},"title":"Annually Report","period":"2024","summary":{"count":5944,"total":2264081.583865003,"commission":221800.07140706936}},"activeProperty":{"count":145,"groupByMonth":{"2024-12":[{"id":1310,"name":"Hope Sapanca Tiny House","commission":15,"year":"2024","month":"2024-12"},{"id":1216,"name":"Hub Inn Pera ","commission":15,"year":"2024","month":"2024-12"},{"id":1224,"name":"Aria Claros Beach & Spa Resort","commission":15,"year":"2024","month":"2024-12"},{"id":1258,"name":"Rayelin Hotel Istanbul Old City","commission":15,"year":"2024","month":"2024-12"},{"id":1218,"name":"StayHub","commission":15,"year":"2024","month":"2024-12"},{"id":1242,"name":"Tusan Beach Resort","commission":15,"year":"2024","month":"2024-12"},{"id":1304,"name":"Litros Hotel & Spa","commission":15,"year":"2024","month":"2024-12"},{"id":1308,"name":"Rayelin Hotel Old Town","commission":15,"year":"2024","month":"2024-12"}],"2024-11":[{"id":1281,"name":"Hotel Atina Budva","commission":15,"year":"2024","month":"2024-11"},{"id":1277,"name":"Villa La Barba","commission":15,"year":"2024","month":"2024-11"},{"id":1275,"name":"S\u00f6\u011f\u00fct Hotel Old City","commission":15,"year":"2024","month":"2024-11"},{"id":1273,"name":"The Riada Hotel","commission":15,"year":"2024","month":"2024-11"},{"id":1269,"name":"Hotel Del Lago Luxury by Sara\u00e7o\u011flu","commission":15,"year":"2024","month":"2024-11"},{"id":1293,"name":"Blue Ottoman Hotel","commission":15,"year":"2024","month":"2024-11"},{"id":1303,"name":"Zelve Hotel","commission":15,"year":"2024","month":"2024-11"},{"id":1276,"name":"Grand S Hotel","commission":15,"year":"2024","month":"2024-11"}],"2024-10":[{"id":1244,"name":"B Hotel Bishkek","commission":15,"year":"2024","month":"2024-10"},{"id":1247,"name":"Keten Suites Taksim","commission":15,"year":"2024","month":"2024-10"},{"id":1246,"name":"Ankara Santral Otel","commission":15,"year":"2024","month":"2024-10"},{"id":1253,"name":"Kazda\u011flar\u0131 Allia Thermal Health & Spa","commission":12,"year":"2024","month":"2024-10"},{"id":1249,"name":"Cartoon Hotel","commission":15,"year":"2024","month":"2024-10"},{"id":1267,"name":"Ottoman Hotel Sakarya","commission":15,"year":"2024","month":"2024-10"},{"id":1260,"name":"Monark Hotel Cappadocia","commission":12,"year":"2024","month":"2024-10"}],"2024-09":[{"id":1215,"name":"Hub Suite \u0130stanbul","commission":15,"year":"2024","month":"2024-09"},{"id":1229,"name":"Qlus\u0131ve Hotel","commission":15,"year":"2024","month":"2024-09"},{"id":1231,"name":"Credo Hotel Kotor","commission":15,"year":"2024","month":"2024-09"}],"2024-08":[{"id":1208,"name":"Vicolo Otel","commission":15,"year":"2024","month":"2024-08"},{"id":1205,"name":"Duck Otel","commission":15,"year":"2024","month":"2024-08"},{"id":1203,"name":"Expo Park Hotel","commission":15,"year":"2024","month":"2024-08"},{"id":1200,"name":"Sierra Cave Cappadocia Hotel","commission":15,"year":"2024","month":"2024-08"},{"id":1196,"name":"Lubberona Cave Cappadocia","commission":15,"year":"2024","month":"2024-08"},{"id":1184,"name":"Elephant In The Room Hotel","commission":15,"year":"2024","month":"2024-08"}],"2024-07":[{"id":1166,"name":"Alice Hotel Antalya","commission":15,"year":"2024","month":"2024-07"},{"id":1180,"name":"Keremk\u00f6y Ya\u015fam Platosu","commission":10,"year":"2024","month":"2024-07"},{"id":1170,"name":"Hotel Berke Ranch & Nature","commission":15,"year":"2024","month":"2024-07"}],"2024-06":[{"id":1150,"name":"Konyaalt\u0131 Furkan Family","commission":15,"year":"2024","month":"2024-06"}],"2024-05":[{"id":1125,"name":"Petra Hotel Trabzon","commission":15,"year":"2024","month":"2024-05"}],"2024-04":[{"id":1103,"name":"New Wave 2 Apart-Hotel","commission":12,"year":"2024","month":"2024-04"},{"id":1102,"name":"Cappadocia Villa Comfort Hotel","commission":15,"year":"2024","month":"2024-04"},{"id":1098,"name":"Batumi Palm Hotel","commission":12,"year":"2024","month":"2024-04"},{"id":1091,"name":"Nehir Suit Hotel","commission":15,"year":"2024","month":"2024-04"},{"id":1090,"name":"Mera Park Otel","commission":15,"year":"2024","month":"2024-04"},{"id":1082,"name":"Very Peri Cappadocia ","commission":12,"year":"2024","month":"2024-04"},{"id":1081,"name":"La Vie Cappadocia Cave Hotel","commission":12,"year":"2024","month":"2024-04"}],"2024-03":[{"id":1048,"name":"Side Crown Serenity","commission":15,"year":"2024","month":"2024-03"},{"id":1047,"name":"Side Crown Palace","commission":15,"year":"2024","month":"2024-03"},{"id":1076,"name":"Alia Cave Hotel","commission":9,"year":"2024","month":"2024-03"},{"id":1073,"name":"Mithra Cave Hotel","commission":9,"year":"2024","month":"2024-03"},{"id":1075,"name":"Misty Cave Hotel","commission":9,"year":"2024","month":"2024-03"}],"2024-02":[{"id":1020,"name":"Gamirasu Junior","commission":15,"year":"2024","month":"2024-02"},{"id":1007,"name":"T\u00fcrkay Hotel","commission":12,"year":"2024","month":"2024-02"},{"id":1008,"name":"Tamara Business Antalya","commission":12,"year":"2024","month":"2024-02"},{"id":1010,"name":"Tamara Business Hotel Van","commission":12,"year":"2024","month":"2024-02"},{"id":1011,"name":"Utopia Cave Cappadocia","commission":15,"year":"2024","month":"2024-02"},{"id":1025,"name":"Hotel Monarch Batumi","commission":12,"year":"2024","month":"2024-02"},{"id":1031,"name":"La Perla Cave Cappadocia","commission":15,"year":"2024","month":"2024-02"},{"id":1024,"name":"Hotel Mandalin","commission":15,"year":"2024","month":"2024-02"},{"id":1033,"name":"Saliche Cave Suits","commission":15,"year":"2024","month":"2024-02"},{"id":1034,"name":"Cappadocia Hobbit House","commission":15,"year":"2024","month":"2024-02"},{"id":1035,"name":"Hotel Salvador","commission":12,"year":"2024","month":"2024-02"}],"2024-01":[{"id":1006,"name":"Can Adalya Palace Hotel","commission":12,"year":"2024","month":"2024-01"},{"id":989,"name":"Tantan Cappadocia House","commission":15,"year":"2024","month":"2024-01"},{"id":984,"name":"Cappanar Cave","commission":15,"year":"2024","month":"2024-01"},{"id":983,"name":"Yunak Evleri","commission":9,"year":"2024","month":"2024-01"},{"id":982,"name":"Enjoy Stone House","commission":12,"year":"2024","month":"2024-01"},{"id":981,"name":"Sabiha Sultan Hotel","commission":12,"year":"2024","month":"2024-01"}],"2023-12":[{"id":955,"name":"My Adress Ala\u00e7at\u0131 Otel","commission":15,"year":"2023","month":"2023-12"},{"id":966,"name":"Arya Apart Kundu","commission":15,"year":"2023","month":"2023-12"},{"id":961,"name":"Lorem Hotel","commission":15,"year":"2023","month":"2023-12"},{"id":956,"name":"Alt\u0131noluk Lambada Otel","commission":15,"year":"2023","month":"2023-12"}],"2023-11":[{"id":934,"name":"Transatlantik Hotel & SPA","commission":15,"year":"2023","month":"2023-11"},{"id":944,"name":"Transatlantik Beach Hotel","commission":15,"year":"2023","month":"2023-11"},{"id":928,"name":"Daima Biz Hotel","commission":12,"year":"2023","month":"2023-11"}],"2023-10":[{"id":911,"name":"All Seasons Suites","commission":10,"year":"2023","month":"2023-10"},{"id":909,"name":"All Seasons Hotel","commission":10,"year":"2023","month":"2023-10"},{"id":907,"name":"Grand Hotel G\u00fclsoy","commission":15,"year":"2023","month":"2023-10"},{"id":901,"name":"Emerald Hotel","commission":12,"year":"2023","month":"2023-10"},{"id":912,"name":"Grand Ons Hotel","commission":15,"year":"2023","month":"2023-10"}],"2023-09":[{"id":872,"name":"La Rezidans Hotel","commission":15,"year":"2023","month":"2023-09"}],"2023-08":[{"id":848,"name":"Green Glass Hotel","commission":12,"year":"2023","month":"2023-08"}],"2023-07":[{"id":808,"name":"Nok \u0130stanbul Suites","commission":15,"year":"2023","month":"2023-07"}],"2023-06":[{"id":772,"name":"Cronton Design Hotel","commission":15,"year":"2023","month":"2023-06"},{"id":790,"name":"New Wave Hotel ","commission":12,"year":"2023","month":"2023-06"}],"2023-05":[{"id":738,"name":"VONRESORT Abant","commission":15,"year":"2023","month":"2023-05"},{"id":729,"name":"\u00d6zkaymak Select Resort Hotel","commission":15,"year":"2023","month":"2023-05"},{"id":728,"name":"Lara Din\u00e7 Hotel","commission":15,"year":"2023","month":"2023-05"},{"id":743,"name":"Hotel Luna Antalya","commission":12,"year":"2023","month":"2023-05"},{"id":755,"name":"Hotel Chao","commission":12,"year":"2023","month":"2023-05"},{"id":759,"name":"The Nest Hotel","commission":15,"year":"2023","month":"2023-05"}],"2023-04":[{"id":692,"name":"Orka Royal Hotel & Spa","commission":12,"year":"2023","month":"2023-04"},{"id":696,"name":"Mielo Lara Hotel","commission":15,"year":"2023","month":"2023-04"},{"id":693,"name":"Orient Express & Spa by Orka Hotels","commission":12,"year":"2023","month":"2023-04"},{"id":694,"name":"Pianoforte by Febor Hotels&Spa","commission":12,"year":"2023","month":"2023-04"},{"id":695,"name":"Orka Taksim Suites & Hotel","commission":12,"year":"2023","month":"2023-04"},{"id":726,"name":"\u00d6zkaymak Otem Hotel","commission":15,"year":"2023","month":"2023-04"},{"id":698,"name":"Febor Park Hotel","commission":12,"year":"2023","month":"2023-04"},{"id":699,"name":"Lara Kapris Otel","commission":15,"year":"2023","month":"2023-04"},{"id":712,"name":"G Hotels Skopje","commission":15,"year":"2023","month":"2023-04"},{"id":721,"name":"\u00d6zkaymak \u0130ncekum Hotel","commission":15,"year":"2023","month":"2023-04"},{"id":724,"name":"\u00d6zkaymak Marina Hotel","commission":15,"year":"2023","month":"2023-04"}],"2023-03":[{"id":684,"name":"Alfa Cave Hotel","commission":15,"year":"2023","month":"2023-03"},{"id":681,"name":"The Calypso Cave","commission":15,"year":"2023","month":"2023-03"}],"2023-02":[{"id":665,"name":"Endless Flats","commission":12,"year":"2023","month":"2023-02"},{"id":671,"name":"Bilgehan Hotel","commission":9,"year":"2023","month":"2023-02"},{"id":668,"name":"Sim Hotel","commission":12,"year":"2023","month":"2023-02"}],"2023-01":[{"id":629,"name":"Endless Comfort Hotel","commission":10,"year":"2023","month":"2023-01"},{"id":628,"name":"Endless Suites Taksim","commission":10,"year":"2023","month":"2023-01"},{"id":644,"name":"VONRESORT Golden Coast","commission":15,"year":"2023","month":"2023-01"},{"id":643,"name":"VONRESORT Elite","commission":15,"year":"2023","month":"2023-01"},{"id":645,"name":"VONRESORT Golden Beach","commission":15,"year":"2023","month":"2023-01"}],"2022-12":[{"id":623,"name":"WOW Airport Hotel","commission":15,"year":"2022","month":"2022-12"},{"id":605,"name":"Oksijen Zone Hotel & Spa","commission":15,"year":"2022","month":"2022-12"},{"id":591,"name":"WOW \u0130stanbul Hotel","commission":15,"year":"2022","month":"2022-12"}],"2022-11":[{"id":580,"name":"\u00d6zkaymak Falez Hotel","commission":15,"year":"2022","month":"2022-11"},{"id":529,"name":"Green Nature Resort & Spa Otel","commission":12,"year":"2022","month":"2022-11"}],"2022-10":[{"id":506,"name":"Green Nature Diamond Hotel","commission":12,"year":"2022","month":"2022-10"},{"id":503,"name":"Elegance Hotels International","commission":12,"year":"2022","month":"2022-10"}],"2022-08":[{"id":450,"name":"Bilem Hotel Beach & Spa","commission":15,"year":"2022","month":"2022-08"}],"2022-07":[{"id":430,"name":"Invite Hotel Corner Trabzon","commission":15,"year":"2022","month":"2022-07"}],"2022-05":[{"id":400,"name":"Elanaz Hotel","commission":12,"year":"2022","month":"2022-05"}],"2022-04":[{"id":384,"name":"Albinas Hotel Old City","commission":12,"year":"2022","month":"2022-04"}],"2022-03":[{"id":366,"name":"Sealife Royal Suites","commission":10,"year":"2022","month":"2022-03"},{"id":368,"name":"Sultan Hostel & Guesthouse","commission":12,"year":"2022","month":"2022-03"}],"2022-02":[{"id":362,"name":"Bar\u0131n Hotel","commission":12,"year":"2022","month":"2022-02"}],"2022-01":[{"id":346,"name":"G\u00fcner Business Hotel","commission":12,"year":"2022","month":"2022-01"}],"2021-12":[{"id":317,"name":"Lalahan Hotel","commission":12,"year":"2021","month":"2021-12"},{"id":343,"name":"CitrusLuna Suite Hotel","commission":15,"year":"2021","month":"2021-12"},{"id":341,"name":"Harbiye Residence","commission":12,"year":"2021","month":"2021-12"},{"id":330,"name":"Radar Hotel","commission":12,"year":"2021","month":"2021-12"},{"id":326,"name":"Yavuz Otel","commission":12,"year":"2021","month":"2021-12"},{"id":319,"name":"\u0130lkay Hotel","commission":12,"year":"2021","month":"2021-12"},{"id":318,"name":"Hotellino","commission":12,"year":"2021","month":"2021-12"},{"id":316,"name":"Sirkeci Mansion Hotel","commission":9,"year":"2021","month":"2021-12"},{"id":314,"name":"Hotel \u015eahinler","commission":12,"year":"2021","month":"2021-12"},{"id":313,"name":"Levni Plus Hotel","commission":12,"year":"2021","month":"2021-12"}],"2021-10":[{"id":278,"name":"Gorrion Hotel Istanbul","commission":8,"year":"2021","month":"2021-10"}],"2021-08":[{"id":252,"name":"Tut Hotel","commission":12,"year":"2021","month":"2021-08"}],"2021-07":[{"id":249,"name":"Grand Ant Hotel","commission":12,"year":"2021","month":"2021-07"}],"2021-04":[{"id":236,"name":"Sealife Kemer Resort Hotel","commission":10,"year":"2021","month":"2021-04"}],"2020-11":[{"id":165,"name":"Sealife Lounge Hotel","commission":10,"year":"2020","month":"2020-11"},{"id":164,"name":"SeaLife Family Resort Hotel","commission":10,"year":"2020","month":"2020-11"},{"id":163,"name":"Porto Bello Hotel Resort & Spa","commission":10,"year":"2020","month":"2020-11"},{"id":166,"name":"Sealife Buket Beach & Resort","commission":10,"year":"2020","month":"2020-11"},{"id":168,"name":"Endless Art Hotel Special Category","commission":10,"year":"2020","month":"2020-11"}],"2020-08":[{"id":71,"name":"Grand Yavuz Hotel","commission":15,"year":"2020","month":"2020-08"}]},"lastMonth":{"2024-12":[{"id":1310,"name":"Hope Sapanca Tiny House","commission":15,"year":"2024","month":"2024-12"},{"id":1216,"name":"Hub Inn Pera ","commission":15,"year":"2024","month":"2024-12"},{"id":1224,"name":"Aria Claros Beach & Spa Resort","commission":15,"year":"2024","month":"2024-12"},{"id":1258,"name":"Rayelin Hotel Istanbul Old City","commission":15,"year":"2024","month":"2024-12"},{"id":1218,"name":"StayHub","commission":15,"year":"2024","month":"2024-12"},{"id":1242,"name":"Tusan Beach Resort","commission":15,"year":"2024","month":"2024-12"},{"id":1304,"name":"Litros Hotel & Spa","commission":15,"year":"2024","month":"2024-12"},{"id":1308,"name":"Rayelin Hotel Old Town","commission":15,"year":"2024","month":"2024-12"}],"2024-11":[{"id":1281,"name":"Hotel Atina Budva","commission":15,"year":"2024","month":"2024-11"},{"id":1277,"name":"Villa La Barba","commission":15,"year":"2024","month":"2024-11"},{"id":1275,"name":"S\u00f6\u011f\u00fct Hotel Old City","commission":15,"year":"2024","month":"2024-11"},{"id":1273,"name":"The Riada Hotel","commission":15,"year":"2024","month":"2024-11"},{"id":1269,"name":"Hotel Del Lago Luxury by Sara\u00e7o\u011flu","commission":15,"year":"2024","month":"2024-11"},{"id":1293,"name":"Blue Ottoman Hotel","commission":15,"year":"2024","month":"2024-11"},{"id":1303,"name":"Zelve Hotel","commission":15,"year":"2024","month":"2024-11"},{"id":1276,"name":"Grand S Hotel","commission":15,"year":"2024","month":"2024-11"}],"2024-10":[{"id":1244,"name":"B Hotel Bishkek","commission":15,"year":"2024","month":"2024-10"},{"id":1247,"name":"Keten Suites Taksim","commission":15,"year":"2024","month":"2024-10"},{"id":1246,"name":"Ankara Santral Otel","commission":15,"year":"2024","month":"2024-10"},{"id":1253,"name":"Kazda\u011flar\u0131 Allia Thermal Health & Spa","commission":12,"year":"2024","month":"2024-10"},{"id":1249,"name":"Cartoon Hotel","commission":15,"year":"2024","month":"2024-10"},{"id":1267,"name":"Ottoman Hotel Sakarya","commission":15,"year":"2024","month":"2024-10"},{"id":1260,"name":"Monark Hotel Cappadocia","commission":12,"year":"2024","month":"2024-10"}]}}}',1);
        //$this->mailer->onQueue('dailyReportMail', new DailyReportMail($summaryReportData));

        //dd($summaryReportData);


        //Log::debug($inputAll);


        /*$newBookingNotificationParam = ['property_id' => 1];
        $this->notificationService->sendLogNotification($newBookingNotificationParam);*/


        /*$bookingPropertyAddonUpdateMail = [
            'bookingCode' => 'BKG240814-OYS9A8DG'
        ];
        $this->mailer->onQueue('bookingInvoiceUpdateMail', new BookingInvoiceUpdateMail($bookingPropertyAddonUpdateMail));*/


        /*$paymentDetailParam = [
            'orderCode' => 'LNK230913-ALAXEATT',
            'language_code' => isset($params['language_code']) ? $params['language_code'] : 'en'
        ];
        $this->manualPaymentMailService->process($paymentDetailParam);*/


        //$mailParams = ['booking_id' => 44264];
        //$this->newBookingMailService->process($mailParams);
        //$this->mailer->onQueue('modifiedBookingMail', new ModifiedBookingMail($mailParams));
        //$this->mailer->onQueue('cancelBookingMail', new CancelBookingMail($mailParams));
        //dd('ds');


        //F5k8GvBkLQ22414131
        //Lucpc736tlh2414127
        //w9wAo95tftA2414111 - Success

        try {

            $initializePaymentParam = [
                'propertyId' => 1,
                'orderId' => getCodeGenerate(),
                'installment' => 0,
                'amount' => (double)868.3199999999999,
                'currency' => 'TRY',
                'responseUrl' => 'http://api.extranetwork.local/testResponse',
                'preferredPaymentTypeId' => 325,
                'ipAddress' => $request->getClientIp(),
                'creditCard' => [
                    'name' => 'Burhan Yumak',
                    'number' => '4938460158754205',
                    'month' => '11',
                    'year' => '2024',
                    'cvv' => '715',
                ]
            ];

            //4938460158754205 2024/11 715 123456
            //4119790155203496 2024/04 579

            $initializePayment = $this->propertyPaymentService->initializePayment($initializePaymentParam);

            dd($initializePayment);


            die();

            //BookingPaymentDataCode
            /*$mailParams = [
                'user_id' => 1,
                'booking_id' => 978,
                'unlock_code' => 'KEOSXS',
                //'locale' => 'en'
            ];
            return new BookingPaymentDataCodeMail($mailParams);
                die();
            $this->mailer->onQueue('bookingPaymentDataCode', new BookingPaymentDataCodeMail($mailParams));*/


            $paymentInfo = [
                "creditCard" => [
                    "cardHolder" => "John Doe",
                    "cardNumber" => "5127541122223332",
                    "cardExpireMonth" => "12",
                    "cardExpireYear" => "2022",
                    "cardCvv" => "000",
                    "installment" => 0
                ]
            ];

            $cardNumber = $paymentInfo['creditCard']['cardNumber'];
            $cardLengthSize = ceil(strlen($cardNumber) / 4);

            $cardNumberParse = [];
            for ($i = 0; $i < $cardLengthSize; $i++) {
                $cardNumberParse['cc'][] = Crypt::encrypt(mb_substr($cardNumber, $i * 4, 4));
            }

            $cardNumberParse['cm'] = Crypt::encrypt($paymentInfo['creditCard']['cardExpireMonth']);
            $cardNumberParse['cy'] = Crypt::encrypt(mb_substr($paymentInfo['creditCard']['cardExpireYear'], -2, 2));
            $cardNumberParse['cv'] = Crypt::encrypt($paymentInfo['creditCard']['cardCvv']);

            dd($cardNumberParse, Crypt::decrypt($cardNumberParse['cm']));

            dd(ceil(strlen($paymentInfo['creditCard']['cardNumber']) / 4));

            $param = "3441";
            $x = Crypt::encrypt($param);

            dd($x, strlen($x), Crypt::decrypt($x));

            die();
            $mailParams = ['booking_id' => 10117];
            $this->newBookingMailService->process($mailParams);

            die();


            $mailParams = [];

            $today = '2022-02-25';


            $report['daily']['data'] = [];
            $report['daily']['title'] = 'Daily Report';
            $report['daily']['period'] = Carbon::parse($today)->format('d.m.Y');
            $daily = vwBookingSummary::where('time', '>', Carbon::parse($today)->toDateString())
                ->where('time', '<', Carbon::parse($today)->addDay()->toDateString())
                ->get()->toArray();

            if ($daily) {
                $dataCollect = collect($daily);
                $dataCollectGroup = $dataCollect->groupBy('currency_code')->toArray();
                foreach ($dataCollectGroup as $currencyCode => $currencyGroup) {
                    $report['daily']['data'][$currencyCode]['count'] = count($currencyGroup);
                    $report['daily']['data'][$currencyCode]['total'] = array_sum(pickItemFromArray('total', $currencyGroup));
                }
            }


            $report['monthly']['data'] = [];
            $report['monthly']['title'] = 'Monthly Report';
            $report['monthly']['period'] = Carbon::parse($today)->firstOfMonth()->format('m.Y');
            $monthly = vwBookingSummary::where('time', '>', Carbon::parse($today)->firstOfMonth()->toDateString())
                ->where('time', '<', Carbon::parse($today)->addMonth()->firstOfMonth()->toDateString())
                ->get()->toArray();

            if ($monthly) {
                $dataCollect = collect($monthly);
                $dataCollectGroup = $dataCollect->groupBy('currency_code')->toArray();
                foreach ($dataCollectGroup as $currencyCode => $currencyGroup) {
                    $report['monthly']['data'][$currencyCode]['count'] = count($currencyGroup);
                    $report['monthly']['data'][$currencyCode]['total'] = array_sum(pickItemFromArray('total', $currencyGroup));
                }
            }


            $report['annually']['data'] = [];
            $report['annually']['title'] = 'Annually Report';
            $report['annually']['period'] = Carbon::parse($today)->firstOfYear()->format('Y');
            $annually = vwBookingSummary::where('time', '>', Carbon::parse($today)->firstOfYear()->toDateString())
                ->where('time', '<', Carbon::parse($today)->addYear()->firstOfYear()->toDateString())
                ->get()->toArray();

            if ($annually) {
                $dataCollect = collect($annually);
                $dataCollectGroup = $dataCollect->groupBy('currency_code')->toArray();
                foreach ($dataCollectGroup as $currencyCode => $currencyGroup) {
                    $report['annually']['data'][$currencyCode]['count'] = count($currencyGroup);
                    $report['annually']['data'][$currencyCode]['total'] = array_sum(pickItemFromArray('total', $currencyGroup));
                }
            }


            $this->mailer->onQueue('dailyReportMail', new DailyReportMail($report));


            die();

            //Secret key
            $secretKey = 'sk_test_51HuYHvEa9cmPdLq3ANG7ZYaGB9zMuhQZlwH19axJRauZsMnnpnuGBN1h8iAfr9kNVWe4FWcEcvZiMjn3hhBELHHx00hiBgjO41';
            $stripe = new \Stripe\StripeClient($secretKey);

            //$balance = $stripe->balance->retrieve();
            $balanceTransactions = $stripe->balanceTransactions->all(['limit' => 10]);


            dd($balanceTransactions->toArray());

            $token = $stripe->tokens->create([
                'card' => [
                    'number' => $params['creditCard']['number'],
                    'exp_month' => $params['creditCard']['month'],
                    'exp_year' => $params['creditCard']['year'],
                    'cvc' => $params['creditCard']['cvv']
                ],
            ]);


            die();


            //Bunu bookin sonrası ve booking iptali kısmına koyucaz

            //Connected Room Case
            $roomAvailabilityUpdateForConnectedRoomParams = [
                'property_id' => 1,
                'channel_id' => 1,
                'availability_type_id' => [1],
                'startDate' => '2022-01-18',
                'endDate' => '2022-01-25',
            ];

            $this->propertyRoomAvailabilityService->roomAvailabilityUpdateForConnectedRooms($roomAvailabilityUpdateForConnectedRoomParams);
            //Connected Room Case

            dd('ok');

            $mailParams = ['booking_id' => 1134];
            $this->newBookingMailService->process($mailParams);

            throw new Exception('api-unknown_error');


        } catch (Exception $e) {
            dd($e->getMessage());
            Log::debug($e->getMessage());
        }

        die();

    }
}
