<?php

namespace App\Notifications;

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

class SearchHostel extends Notification implements ShouldQueue{
	use Queueable;

	/**
	 * Create a new notification instance.
	 *
	 * @return void
	 */
	protected $user;
	protected $districtName;
	protected $findSessionId;
	protected $provinceId;
	protected $districtArr;


	public function __construct( $user, $districtName, $findSessionId, $provinceId, $districtArr ) {
		//
		$this->user          = $user;
		$this->districtName  = $districtName;
		$this->findSessionId = $findSessionId;
		$this->provinceId    = $provinceId;
		$this->districtArr   = $districtArr;
	}

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

	public function getText() {
		$findSession = FindSession::find( $this->findSessionId );
		$minPrice    = 0;
		$maxPrice    = 0;
		if ( $findSession ) {
			$minPrice = $findSession->min_price;
			$maxPrice = $findSession->max_price;
		}
	}

	public function toPush( $notifiable ) {

		$text = Functions::getNotificationSearchText( $this->findSessionId, $this->districtName );

		return [
			'type'            => 'SEARCH',
			'object_id'       => $this->user->id,
			'body'            => $text,
			'title'           => '🤩Có khách đang tìm nhà này bạn ơi 🤩',
			'image'           => $this->user->image,
			'find_session_id' => $this->findSessionId,
			'province_id'     => $this->provinceId,
			'districts'       => $this->districtArr
		];
	}

	/**
	 * 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 ) {
		$text = Functions::getNotificationSearchText( $this->findSessionId, $this->districtName );

		return [
			'type'      => 'SEARCH',
			'object_id' => $this->user->id,
			'text'      => $text,
			'title'     => 'Có một thông báo tìm trọ gần bạn',
			'image'     => $this->user->image,
			'province_id'     => $this->provinceId,
			'districts'       => $this->districtArr
		];
	}
}
