<?php
/**
 * Created by PhpStorm.
 * User: sunil
 * Date: 9/29/18
 * Time: 4:30 PM
 */

namespace App\Console\Commands;

use App\Http\Controllers\Admin\RepaymentController;
use App\Slack;
use Illuminate\Console\Command;
use Illuminate\Http\Request;

class HomevilleRPS extends Command
{
    protected $signature = 'homeVilleRPS:fetch {--application_id=}';


    public function __construct(){
        parent::__construct();
    }


    public function handle(){
        $this->callHomeVilleRPS();
    }


    public function callHomeVilleRPS(){
        try {
            if (\app()->runningInConsole() && $this->option('application_id')) {
                $repaymentController = new RepaymentController();
                $response = $repaymentController->fetchHomeVilleRPS($this->option('application_id'));
                if (isset($response['status']) && $response['status'] == 'OK'){
                    $this->comment($response['message']);
                    if (isset($response['data'])) {
                        $this->comment(json_encode($response['data']));
                    }
                }else{
                    $this->comment(json_encode($response));
                }
            } else {
                $this->comment('No Id passed');
            }
        }catch (\Exception $e){
            $this->comment($e->getMessage(), '|'. $e->getFile().'|'. $e->getLine());
        }
    }
}
