<?php

namespace App\Modules\Network\Commands;

use App\Events\SimplePrivateEvent;
use App\Helpers\ClickhouseHandler;
use App\Modules\Network\Models\Goliath\GoliathRegion;
use App\Modules\Network\Models\Goliath\GoliathSubregion;
use App\Modules\Network\Models\Goliath\GoliathMetro;
use Carbon\Carbon;
use Illuminate\Support\Facades\Validator;

class Test extends \App\Console\Commands\BaseCommand
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'network:test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Runs the playground development script for debugging and testing.';

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

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $regex = '/((?:\sor|and\s)*dst (?:host|net) (?:(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]){0,3})(?:\/\d+)?(?:\s(?:or|and)\s)*)|(?:(?:\sor\s)*dst (?:host|net) (?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?(?:\/\d+)?(?:\s(?:or|and)\s)*)/';
        $subject = "dst host 198.51.100.213 or dst host 1.2.2.2 or dst host 1.2.2.2 or dst host fe80::aebc:32ff:fe84:70b7 or udp and src port 2005";

        //dst host 198.51.100.259 or dst host 1.2.2.2/32 or dst host 1.2.2.2 or dst host ::aebc:32ff::fe84:70b7/64

        $matches = [];
        preg_match_all($regex, $subject, $matches);

        \Log::debug($matches[0]);

        foreach($matches[0] as $removable) {
            $subject = str_replace($removable, '', $subject);
        }

        \Log::debug($subject);
    
        return 0;
    }
}