<?php

namespace App\Notification\Notifications;

use App\Browser\JobDebugScreenshot;
use App\Notification\Notification;
use App\Notification\NotificationBody\JobDebugNotificationBody;
use App\Notification\Stringifiable;
use App\Notification\Stringifiable\StringifiableSimpleText;
use Illuminate\Support\Facades\Log;

class JobDebugNotification extends Notification {

    private string|null $title;
    private string|null $screenShotProjectPath;

    public function __construct(int $jobId, string $body, string $title = null, string $error = null, ?string $screenshotProjectPath = "", bool $isError = true) {
        parent::__construct($jobId, isError:$isError);
        $this->title = $title;
        if ($screenshotProjectPath === "") {
            $screenshotProjectPath = JobDebugScreenshot::getImgFileProjectPath($jobId);
        }
        $this->screenShotProjectPath = $screenshotProjectPath;
        $this->setBody(new JobDebugNotificationBody($this->job, $body, $error, $this->screenShotProjectPath != null));
    }

    public function getTitle(): Stringifiable {
        return new StringifiableSimpleText($this->title ?? "DEBUG Job {$this->job->name}");
    }

    /**
     * @inheritDoc
     */
    public function getImageProjectPath(): string|null {
        return $this->screenShotProjectPath;
    }

    /**
     * @inheritDoc
     */
    public function getLinkURL(): string|null {
        return route('jobs.show', ['job' => $this->job->id]);
    }
}
