<?php

namespace App\Notifications;

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

class RemindOwnerWhenRenterRate extends Notification implements ShouldQueue {
	use Queueable;

	/**
	 * Create a new notification instance.
	 *
	 * @return void
	 */
	protected $hostel;
	protected $user;
	protected $rating;
	protected $content;

	public function __construct( $hostel, $user, $rating, $content ) {
		//
		$this->hostel  = $hostel;
		$this->user    = $user;
		$this->rating  = $rating;
		$this->content = $content;
	}

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

	public function toPush( $notifiable ) {

		if ( $this->rating <= 1 ) {
			$rate = 'rất tệ';
		} else if ( $this->rating <= 2 ) {
			$rate = 'tệ';
		} else if ( $this->rating <= 3 ) {
			$rate = 'bình thường';
		} else if ( $this->rating <= 4 ) {
			$rate = 'tốt';
		} else if ( $this->rating <= 5 ) {
			$rate = 'rất tốt';
		}

		return [
			'type'      => config( 'constants.RATING' ),
			'object_id' => $this->hostel->id,
			'body'      => $this->content,
			'title'     => $this->user->name_text . ' đã đánh giá nhà bạn ở mức ' . $rate,
			'image'     => $this->user->image,
		];
	}

	/**
	 * 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 [
			//
		];
	}
}
