<?php

namespace App\Notifications;

use App\Models\Report;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class ItemReported extends Notification implements ShouldQueue
{
    use Queueable;

    /**
     * Create a new notification instance.
     */
    public function __construct(
        private Report $report
    ) {
    }

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

    /**
     * Get the mail representation of the notification.
     */
    public function toMail(object $notifiable): MailMessage
    {
        $adminUrl = route('admin.reports.index');

        $reasonLabel = array_flip(Report::getReasonOptions())[$this->report->reason] ?? $this->report->reason;

        return (new MailMessage)
            ->subject("New Report Submitted - Action Required")
            ->greeting("New Report Received")
            ->line("An item has been reported for review.")
            ->line('')
            ->line("Item: {$this->report->item->title}")
            ->line("Item ID: {$this->report->item->id}")
            ->line("Reported By: {$this->report->reporter->name}")
            ->line("Reason: {$reasonLabel}")
            ->when($this->report->description, function ($mail) {
                return $mail->line("Description: {$this->report->description}");
            })
            ->line('')
            ->action('Review Report', $adminUrl)
            ->line('Please review this report and take appropriate action.');
    }
}
