<?php

namespace App\Notifications\Api\App;

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

class AutoCancelTripNotification extends Notification
{
    use Queueable;

    protected $via;
    protected $trip_id;
    private $title, $body;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($trip_id, $via)
    {
        $this->via     = $via;
        $this->trip_id = $trip_id;

        $this->title   = [
            'ar' => trans('The ride was automatically canceled', [], 'ar'),
            'en' => trans('The ride was automatically canceled', [], 'en'),
        ];
        
        $this->body    = [
            'ar' => trans('The ride was automatically canceled due to the expiration of the waiting time to start the ride', [], 'ar'),
            'en' => trans('The ride was automatically canceled due to the expiration of the waiting time to start the ride', [], 'en'),
        ];
    }

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

    public function toFcm($notifiable)
    {
        return [
            'notify_type'   => 'trip',
            'notify_id'     => $this->trip_id,
            'notify_status' => "auto_cancel",
            'title'         => $this->title[$notifiable->locale ?? 'en'],
            'body'          => $this->body[$notifiable->locale ?? 'en'],
            'sender_data'   => auth('api')->user()?->only(['id', 'full_name', 'avatar']),
        ];
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            'notify_type'   => 'trip',
            'notify_id'     => $this->trip_id,
            'notify_status' => "auto_cancel",
            'title'         => $this->title,
            'body'          => $this->body,
            'sender_data'   => auth('api')->user()?->only(['id', 'full_name', 'avatar']),
        ];
    }
}
