<?php

namespace App\Console\Commands;

use App\Support\NavClient;
use Illuminate\Console\Command;

class GetProduct extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'noldus:get-product {product_no}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Gets product from navision';

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

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $productNo = $this->argument('product_no');
        if (!$productNo) {
            $this->error('You have to specify the product nav number');
            return 0;
        }

        $client = new NavClient();

        $productData = $client->getItem($productNo);

        echo json_encode($productData);

        $priceData = $client->getPrice($productNo);

        echo json_encode($priceData);

        return 0;
    }
}
