<?php

namespace App\Notifications;

use App\Models\ProductReservation;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class ProductReservationRequested extends Notification
{
    public function __construct(
        public ProductReservation $reservation
    ) {}

    public function via(object $notifiable): array
    {
        $channels = ['database'];
        if (app()->environment('production')) {
            $channels[] = 'mail';
        }

        return $channels;
    }

    public function toMail(object $notifiable): MailMessage
    {
        $p = $this->reservation->product;

        return (new MailMessage)
            ->subject('Yeni canlı yem rezervasyon talebi')
            ->greeting('Merhaba '.$notifiable->name.'!')
            ->line(($p ? $p->name : 'Ürün').' için '.$this->reservation->quantity.' adet rezervasyon talebi aldınız.')
            ->line('Uygulama üzerinden mağaza panelinden talebi onaylayabilir veya reddedebilirsiniz.')
            ->line('Teşekkürler.');
    }

    public function toArray(object $notifiable): array
    {
        $p = $this->reservation->product;

        return [
            'type' => 'product_reservation_requested',
            'title' => 'Yeni ürün rezervasyon talebi',
            'message' => ($p ? $p->name : 'Ürün').' — '.$this->reservation->quantity.' adet',
            'product_reservation_id' => $this->reservation->id,
            'product_id' => $this->reservation->product_id,
            'quantity' => $this->reservation->quantity,
            'status' => $this->reservation->status->value,
            'action_url' => '/seller/product-reservations',
        ];
    }
}
