<?php

namespace App\Providers;

use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Opcodes\LogViewer\Facades\LogViewer;
use Opcodes\LogViewer\LogLevels\LaravelLogLevel;
use Opcodes\LogViewer\Logs\Log;
use Opcodes\LogViewer\Utils\Utils;
use Opcodes\MailParser\Message;

class SynologySSLog extends Log
{
    public static string $name = 'SynologySS';
    //public static string $regex = '/^\[(?P<datetime>[^\]]+)\] (?P<environment>\S+)\.(?P<level>\S+): ?(\|(?<pid>\S+)\|)? (?P<message>.*)? (\{(?<data>\S+)\}) ?(\[(?<extra>\S+|)\])?/';
    //public static string $regex = '/^\[(?P<datetime>[^\]]+)\] (?P<environment>\S+)\.(?P<level>\S+): ?(\|(?<pid>\S+)\|)? ?(\((?<class>\S+)\))? (?P<message>.*)? ((?<data>(\{\S+\})|(\[\]))) ((?<extra>(\{\S+\})|(\[\])))/';
    public static string $regex = '/^\[(?P<datetime>[^\]]+)\] (?P<environment>\S+)\.(?P<level>\S+): ?(\|(?<pid>\S+)\|)? ?(\((?<class>\S+)\))? (?P<message>.*)? ((?<data>(\{.*\})|(\[.*\]))) ((?<extra>(\{\S+\})|(\[\])))/';
    /** @var array|\string[][] The columns displayed on the frontend, and which data they should display */
    public static array $columns = [
        ['label' => 'Datetime', 'data_path' => 'datetime'],
        ['label' => 'Level', 'data_path' => 'level'],
        ['label' => 'Pid', 'data_path' => 'context.pid'],
        ['label' => 'Class', 'data_path' => 'context.class'],
        ['label' => 'Message', 'data_path' => 'context.message'],
        ['label' => 'Data', 'data_path' => 'context.data'],
    ];

    public function fillMatches(array $matches = []): void
    {
        // The parent class already handles the "datetime", "level" and "message" matches. But you're free to assign them yourself.
        parent::fillMatches($matches);

        $this->context = [
            'datetime' => $matches['datetime'],
            'environment' => $matches['environment'],
            'level' => $matches['level'],
            'pid' => $matches['pid'],
            'class' => $matches['class'],
            'message' => $matches['message'],
            'data' => $matches['data'],
            'extra' => $matches['extra'],
        ];
    }

}
