<?php

namespace App\Notifications;

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

class VoidRequestNotification extends Notification
{
    use Queueable;

    public function __construct(
        private Sale $sale,
        private string $action,
        private string $message,
        private ?string $actorName = null,
    ) {}

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

    public function toArray(object $notifiable): array
    {
        return [
            'title'       => $this->getTitle(),
            'message'     => $this->message,
            'sale_id'     => $this->sale->id,
            'order_no'    => $this->sale->order_no,
            'action'      => $this->action,
            'actor_name'  => $this->actorName,
            'url'         => '/penjualan?id=' . $this->sale->id,
        ];
    }

    private function getTitle(): string
    {
        return match ($this->action) {
            'request'  => 'Pengajuan Void Transaksi',
            'approved' => 'Void Transaksi Disetujui',
            'rejected' => 'Void Transaksi Ditolak',
            default    => 'Update Void Transaksi',
        };
    }
}
