<?php

namespace App\Console\Commands;

use Carbon\Carbon;
use DB;
use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Config;

class FixSMS extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'fix:sms';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Display an inspiring quote';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {

        $this->info('CONNECTING TO SERVER 3');

        $data = DB::connection('s3')->table('pending_single_sms')->get();
            foreach ($data as $src)
            {
                $this->info(json_encode($src));
                try
                {
                    $exe = DB::connection('remote')->table('pending_single_sms')->insert([
                        'msisdn'        => $src->msisdn,
                        'sender'        => $src->sender,
                        'message'       => $src->message,
                        'sched_datetime'=> $src->sched_datetime,
                        'user_id'       => $src->user_id,
                        'created_at'    => $src->created_at,
                        'type'          => $src->type,
                        'bpid'          => $src->bpid
                    ]);

                    DB::connection('s3')->table('pending_single_sms')->delete($src->id);
                }
                catch (\Exception $x){
                    $this->warn(json_encode($src));
                };
            }
            $this->info('DONE INSERTING RECORDS');

        return null;
    }
}
