<?php

namespace App\Console\Commands;

use App\Support\NavClient;
use Illuminate\Console\Command;

class GetContact extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'noldus:get-contact {contact_no}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Gets contact from navision';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $contactNo = $this->argument('contact_no');
        if (!$contactNo) {
            $this->error('You have to specify the contact nav number');
            return 0;
        }

        $client = new NavClient();

        $contactData = $client->getContact($contactNo);

        echo json_encode($contactData);
        return 0;
    }
}
