<?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\TicketMessage;

class AdminResponseNotification extends Notification implements ShouldQueue
{
    use Queueable;

    protected TicketMessage $ticketMessage;

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

    /**
     * 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_admin_response.subject', [
                'reference_id' => $this->ticketMessage->ticket->reference_id,
                'subject' => $this->ticketMessage->ticket->subject,
            ]))->markdown('emails.ticket.admin_response', [
                'ticketMessage' => $this->ticketMessage
            ]);
    }

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

    public function getMessageDetails($data)
    {
        return [
            'icon' => 'fa-headset',
            'text' => "Admin responded to ticket [{$data['reference_id']}].",
            'link' => route('helpdesk.tickets.show', [$data['id']]),
        ];
    }
}
