<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

use App\Classes\Protocol\Binkd as BinkdClass;
use App\Classes\Sock\SocketClient;
use App\Models\Node;

class BinkpSend extends Command
{
	/**
	 * The name and signature of the console command.
	 *
	 * @var string
	 */
	protected $signature = 'binkp:send {ftn : FTN to Send to}';

	/**
	 * The console command description.
	 *
	 * @var string
	 */
	protected $description = 'Binkp send';

	/**
	 * Execute the console command.
	 *
	 * @return mixed
	 * @throws \App\Classes\Sock\SocketException
	 */
	public function handle()
	{
		Log::info('Call BINKP send');

		$no = Node::findFTN($this->argument('ftn'));

		$client = SocketClient::create($no->address,$no->port);

		$o = new BinkdClass;
		$o->session(BinkdClass::SESSION_BINKP,$client,$no);

		Log::info(sprintf('Connection ended: %s',$client->getAddress()),['m'=>__METHOD__]);
	}
}