<?php

namespace App\Modules\Procurement\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use App\Modules\Procurement\Models\PurchaseOrder;

class NewPurchaseOrder extends Notification
{
    use Queueable;

    protected $purchaseOrder;
    protected $creatorName;

    /**
     * Create a new notification instance.
     */
    public function __construct(PurchaseOrder $purchaseOrder, string $creatorName)
    {
        $this->purchaseOrder = $purchaseOrder;
        $this->creatorName = $creatorName;
    }

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

    /**
     * Get the array representation of the notification.
     *
     * @return array<string, mixed>
     */
    public function toArray(object $notifiable): array
    {
        return [
            'type' => 'purchase_order',
            'action' => 'created',
            'purchase_order_id' => $this->purchaseOrder->id,
            'code' => $this->purchaseOrder->code,
            'creator_name' => $this->creatorName,
            'message' => "{$this->creatorName} 建立了新的採購單：{$this->purchaseOrder->code}",
            'link' => route('purchase-orders.index', ['search' => $this->purchaseOrder->code]), // 暫時導向列表並搜尋，若有詳情頁可改
        ];
    }
}
