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