<?php

namespace App\Notifications;

use App\Broadcasting\PushNotification;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class SearchHostelRenter extends Notification implements ShouldQueue{
	use Queueable;

	/**
	 * Create a new notification instance.
	 *
	 * @return void
	 */
	protected $findSession;
	protected $address;

	public function __construct( $findSession, $address ) {
		//
		$this->findSession = $findSession;
		$this->address     = $address;
	}

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

	/**
	 * Get the mail representation of the notification.
	 *
	 * @param mixed $notifiable
	 *
	 * @return \Illuminate\Notifications\Messages\MailMessage
	 */
	public function toMail( $notifiable ) {
		return ( new MailMessage )
			->line( 'The introduction to the notification.' )
			->action( 'Notification Action', url( '/' ) )
			->line( 'Thank you for using our application!' );
	}

	/**
	 * Get the array representation of the notification.
	 *
	 * @param mixed $notifiable
	 *
	 * @return array
	 */
	public function toArray( $notifiable ) {
		return [
			'type'      => 'SESSION',
			'object_id' => $this->findSession->id,
			'text'      => 'Yêu cầu tìm nhà của bạn tại khu vực ' . $this->address . ' đã được gửi tới các chủ trọ có phòng trống tại khu vực này. Hãy chờ đợi các chủ trọ nhắn tin tới bạn nhé!',
			'body'      => 'Yêu cầu tìm nhà của bạn tại khu vực ' . $this->address . ' đã được gửi tới các chủ trọ có phòng trống tại khu vực này. Hãy chờ đợi các chủ trọ nhắn tin tới bạn nhé!',
			'title'     => 'Itro thông báo',
			'find_session_id' => $this->findSession->id
		];
	}

	public function toPush( $notifiable ) {
		return [
			'type'      => 'SESSION',
			'object_id' => $this->findSession->id,
			'body'      => 'Yêu cầu tìm nhà của bạn tại khu vực ' . $this->address . ' đã được gửi tới các chủ trọ có phòng trống tại khu vực này. Hãy chờ đợi các chủ trọ nhắn tin tới bạn nhé!',
			'title'     => 'Yêu cầu tìm nhà của bạn tại khu vực ' . $this->address . ' đã được gửi tới các chủ trọ có phòng trống tại khu vực này. Hãy chờ đợi các chủ trọ nhắn tin tới bạn nhé!',
			'find_session_id' => $this->findSession->id
		];
	}
}
