<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

use App\Models\{Site,Supplier};
use App\Jobs\SupplierDomainSync as Job;

class SupplierDomainSync extends Command
{
	/**
	 * The name and signature of the console command.
	 *
	 * @var string
	 */
	protected $signature = 'supplier:domain:sync'
	.' {siteid : Site ID}'
	.' {supplier : Supplier Name}'
	.' {--f|forceprod : Force Prod API on dev environment}';

	/**
	 * The console command description.
	 *
	 * @var string
	 */
	protected $description = 'Sync domains from a supplier';

	/**
	 * Execute the console command.
	 *
	 * @return int
	 */
	public function handle()
	{
		$so = Supplier::where('name',$this->argument('supplier'))->singleOrFail();

		Job::dispatchSync(Site::findOrFail($this->argument('siteid')),$so,$this->option('forceprod'));
	}
}