<?php

namespace App\Console\Commands\Intuit;

use Illuminate\Console\Command;
use Intuit\Exceptions\NotTokenException;
use Intuit\Traits\ProviderTokenTrait;

use App\Jobs\AccountingAccountSync;

/**
 * Synchronise Customers with Accounts
 */
class AccountSync extends Command
{
	use ProviderTokenTrait;

	/**
	 * The name and signature of the console command.
	 *
	 * @var string
	 */
	protected $signature = 'intuit:account:sync'
		.' {user? : User Email}';

	/**
	 * The console command description.
	 *
	 * @var string
	 */
	protected $description = 'Synchronise accounts with quickbooks';

	/**
	 * Execute the console command.
	 *
	 * @return int
	 * @throws NotTokenException
	 */
	public function handle()
	{
		AccountingAccountSync::dispatchSync($this->providerToken($this->argument('user')));

		return self::SUCCESS;
	}
}