<?php

namespace App\Console\Commands;

//namespace App\Console\Commands;
use App\Jobs\Job;
use App\Modules\Bookings\Task;
use Illuminate\Console\Command;
use LaravelFCM\Message\OptionsBuilder;
use LaravelFCM\Message\OptionsPriorities;
use LaravelFCM\Message\PayloadDataBuilder;
use LaravelFCM\Message\PayloadNotificationBuilder;
//use \Mail;



class FirebaseNotificationTest extends Command
{
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'fcm:test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Send a feedback (on google) reminder email';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }


    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $targetPartial = '{
            "title":"test_title",
            "body":"test_body",
            "badge":"test_badge",
            "sound":"test_sound"
        }';

        $this->info('Test');
        $optionBuilder = new OptionsBuilder();
        $optionBuilder->setTimeToLive(60*20)
        ->setPriority(OptionsPriorities::high);
        
        $notificationBuilder = new PayloadNotificationBuilder('my title');
        $notificationBuilder->setBody('Hello world')
                            ->setSound('default')
                            ->setBodyLocationKey('test_body_key')
                            ->setIcon('test_icon');
                            
        $dataBuilder = new PayloadDataBuilder();
        $dataBuilder->addData(['repairid' => '103638'])
        ->addData(['repairpin' => '1640'])
        ->addData(['title' => 'Test'])
        ->addData(['body' => 'Hello test'])
        ->addData(['priority' => 'high'])
        ->addData(['number' => '10'])
        ->addData(['show_in_foreground' => true])
        ->addData(['opened_from_tray' => 1]);
        
     
        $option = $optionBuilder->build();
        $notification = $notificationBuilder->build();        
        $data = $dataBuilder->build();

        print('Notification: '  . '\n');
        print_r($notification);
        print('Option: '  . '\n');
        print_r($option);
        print('Data: '  . '\n');
        print_r($data);
        //$token = 'edcZm_sZQD4:APA91bFeCElffZ4IqO41DxQyraYOtI6xjcPtH9qHOsJyEPkj4U3X4ROXgjYq2b7j_aRxOH6_GfeQpFU5DYYp6WB-lCTICuOi1usIx4sfqTPIW95ZrtCtnHYWjpV08GnwhmGoFMrOsSGl';
        //$token = "fK0uav8RtS4:APA91bFGmyG_Rtt2pnBZAHZ35VRrQ4gRZ_Y4Kh-bdxLD0-LLT0quATdK3Hrk4sleCgvJcSgb5zZpVqGxomVD2kXN1WRKZ_t8hxyUwtt3Npje9XzP6KgTStfSM5UErIdoxwfkZp-xBqe0";
        $token = "eDjr5uhoO60:APA91bEvsXCMWVkoLgTD7_VhYqeov5EJM_0p8oPIenPa1U1UVy5Ef6RuOGre_TjYH9jTzOuhRi15GqpKxCkun0fiz8Ii-lYyMjSfdf8WyfHtE_pTHI_hu4kXTEcVDPw11ROmPt1x_J_Y";
        
        $downstreamResponse = FCM::sendTo($token, $option, $notification, $data);

        print('downstreamResponse: '  . '\n');
        print_r($downstreamResponse);
        
       
        $this->info("Number of Successes: " . $downstreamResponse->numberSuccess());
        $this->info("Number of Failures: " . $downstreamResponse->numberFailure());
        $this->info("Number of Modifications: " . $downstreamResponse->numberModification());
/*         $this->info("Tokens to delete:");
        //return Array - you must remove all this tokens in your database
        print_r($downstreamResponse->tokensToDelete());
        
        //return Array (key : oldToken, value : new token - you must change the token in your database )
        $this->info("Tokens to replace - old token and new token");
        print_r($downstreamResponse->tokensToModify());
        
        $this->info("Tokens to resend");
        //return Array - you should try to resend the message to the tokens in the array
        print_r($downstreamResponse->tokensToRetry()); */

    }


}
