<?php

namespace App\Notifications\Ticket;

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

class TicketClosureNotification extends Notification implements ShouldQueue
{
    use Queueable;

    protected Ticket $ticket;

    /**
     * Create a new notification instance.
     */
    public function __construct(Ticket $ticket)
    {
        $this->ticket = $ticket;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @return array<int, string>
     */
    public function via(object $notifiable): array
    {
        return ['mail', 'database'];
    }

    /**
     * Get the mail representation of the notification.
     */
    public function toMail(object $notifiable): MailMessage
    {
        return (new MailMessage)
            ->subject(trans('email.ticket_closure.subject', [
                'reference_id' => $this->ticket->reference_id,
                'status' => $this->ticket->status,
            ]))->markdown('emails.ticket.ticket_closure', [
                'ticket' => $this->ticket
            ]);
    }

    /**
     * Get the array representation of the notification.
     *
     * @return array<string, mixed>
     */
    public function toArray(object $notifiable): array
    {
        return [
            'id' => $this->ticket->id,
            'reference_id' => $this->ticket->reference_id,
        ];
    }

    public function getMessageDetails($data)
    {
        return [
            'icon' => 'fa-headset',
            'text' => "Ticket [{$data['reference_id']}] has been resolved/closed.",
            'link' => route('helpdesk.tickets.show', [$data['id']]),
        ];
    }
}
