<?php

namespace App\Notifications;

use App\Facades\Settings;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Mtc\ContentManager\Contracts\VersionModel;
use Mtc\MercuryDataModels\Tools\UiUrlGenerator;

class PageVersionMarkedToBeReviewed extends Notification
{
    use Queueable;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(private readonly VersionModel $version)
    {
        //
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        $url = '/manage-content/content/edit/' . $this->version->page_id . '/version/' . $this->version->id;
        return new MailMessage()
            ->subject("Page {$this->version->page->title} is pending review - " . Settings::get('app-name'))
            ->line($this->page->author->name . " has marked their version on page '{$this->version->page->title}' "
                . " as Pending Review")
            ->action('Review page version', UiUrlGenerator::make($url));
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}
