<?php

namespace App\Notifications\Frontend\User;

use App\Models\OrderManagement\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\BroadcastMessage;
use Illuminate\Notifications\Notification;

class OrderStatusNotification extends Notification implements ShouldQueue{
    use Queueable;

    public $order;

    /**
     * Create a new notification instance.
     *
     * @param Order $order
     */
    public function __construct(Order $order){
        $this->order = $order;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable){
        return ['database', 'broadcast'];
    }

    public function toDatabase($notifiable): array{
        return $this->data();
    }

    public function toBroadcast($notifiable): BroadcastMessage{
        return new BroadcastMessage([
            'data' => $this->data(),
        ]);
    }

    protected function data(): array{
        $lastStatus = $this->order->status;
        return [
            'order_id' => $this->order->id,
            'order_ref' => $this->order->ref_id,
            'active' => $lastStatus,
            'order_url' => route('user.orders'),
       //     'created_date' => format_date($lastStatus->created_at,__("d-m-Y")),
            'created_date' => format_date($this->order->created_at,__("d-m-Y")),
            'description' => __(""),
        ];
    }
}
