<?php

namespace App\Notifications;

use App\Models\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;

class OrderStatusChangedNotification extends Notification
{
    use Queueable;

    public function __construct(
        protected Order $order,
        protected string $oldStatus,
        protected string $newStatus
    ) {}

    public function via(object $notifiable): array
    {
        return ['database'];
    }

    public function toDatabase(object $notifiable): array
    {
        $labels = Order::getStatusLabels();
        $oldLabel = $labels[$this->oldStatus] ?? $this->oldStatus;
        $newLabel = $labels[$this->newStatus] ?? $this->newStatus;

        $icon = match ($this->newStatus) {
            Order::STATUS_PROCESSING => 'heroicon-o-cog-6-tooth',
            Order::STATUS_SHIPPING => 'heroicon-o-truck',
            Order::STATUS_DELIVERED => 'heroicon-o-check-badge',
            Order::STATUS_RETURNED => 'heroicon-o-arrow-uturn-left',
            default => 'heroicon-o-bell',
        };

        $color = match ($this->newStatus) {
            Order::STATUS_PROCESSING => 'primary',
            Order::STATUS_SHIPPING => 'warning',
            Order::STATUS_DELIVERED => 'success',
            Order::STATUS_RETURNED => 'danger',
            default => 'info',
        };

        return [
            'title' => "تحديث الطلب #{$this->order->id}",
            'body' => "تم تغيير حالة طلبك من \"{$oldLabel}\" إلى \"{$newLabel}\"",
            'icon' => $icon,
            'iconColor' => $color,
            'order_id' => $this->order->id,
            'old_status' => $this->oldStatus,
            'new_status' => $this->newStatus,
        ];
    }
}
