<?php

namespace App\Notification\NotificationBody;

use App\Models\Job;
use App\Notification\NotificationBody;
use App\Notification\Stringifiable;

class JobDebugNotificationBody extends NotificationBody {

    private Job $job;
    private string $body;
    private ?string $error;
    private bool $hasScreenshot;

    public function __construct(Job $job, string $body, string $error = null, bool $hasScreenshot = false) {
        $this->job = $job;
        $this->body = $body;
        $this->error = $error;
        $this->hasScreenshot = $hasScreenshot;
    }

    private function constructString(bool $inMarkdown = false) {
        $mdBody = "";
        if ($this->body !== null) {
            $mdBody .= $this->body;
        }
        if ($this->error !== null) {
            $errorWrapper = $inMarkdown ? "```" : "";
            $mdBody .= " :\n" . $errorWrapper . $this->error . $errorWrapper;
        }
        if ($inMarkdown && $this->hasScreenshot) {
            $mdBody .= "\nScreenshot : ";
        }
        return $mdBody;
    }

    /**
     * @inheritDoc
     */
    public function toMarkdownString(): string {
        return $this->constructString(true);
    }

    /**
     * @inheritDoc
     */
    public function toString(): string {
        return $this->constructString();
    }
}
