<?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 CustomerResponseNotification 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.customer_response.subject', [
                'reference_id' => $this->ticketMessage->ticket->reference_id
            ]))->markdown('emails.ticket.customer_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' => 'ti-headphone-alt',
            'text' => "Customer responded to ticket [{$data['reference_id']}].",
            'link' => route('ch-admin.ticket.show', [$data['id']]),
        ];
    }
}
