<?php

namespace App\Console\Commands;

use App\Services\Navision\ContactsService;
use Illuminate\Console\Command;

class SyncNavCompany extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'noldus:sync-nav-company {company_no} {--force : Force sync companies}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Gets companies from NAV and syncs already existing companies';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle(ContactsService $service)
    {
        $companyNo = $this->argument('company_no');
        if (!$companyNo) {
            $this->error('You have to specify the company nav number');
            return 0;
        }
        $forceSync = $this->option('force');

        $service->getAndSyncCompany($companyNo, $forceSync);

        return 0;
    }
}
