<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use App\Admin;
use App\ProductionOrder;

class NewProductionOrder extends Notification implements ShouldQueue
{
    use Queueable;

    public $fromUser;
    public $productionOrder;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(Admin $admin, ProductionOrder $productionOrder)
    {
        $this->fromUser = $admin;
        $this->productionOrder = $productionOrder;
    }

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

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        $subject = sprintf('Napravljen je napravljen novi radni nalog od strane %s', $this->fromUser->fullName);
        $greeting = sprintf('Pozdrav %s!', $notifiable->fullName);

        return (new MailMessage)
            ->subject($subject)
            ->greeting($greeting)
            ->line('Obavestavamo Vas da je napravljen novi radni nalog.')
            ->action('Pogledaj radni nalog', route('admin.productionOrder.show', ['productionOrder' => $this->productionOrder->pro_id]));
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }


    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toDatabase ($notifiable)
    {
        return [
            'pro_id' => $this->productionOrder->pro_id,
            'warehouse' => $this->productionOrder->warehouse->wh_name,
            'amount' => $this->productionOrder->po_total,
        ];
    }
}
