<?php

namespace App\Notifications;

use App\Broadcasting\DatabaseNotificationOld;
use App\Broadcasting\PushNotification;
use App\Broadcasting\PushNotificationOld;
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 SearchHostelManageApp extends Notification implements ShouldQueue
{
    use Queueable;

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

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

    /**
     * Get the notification's delivery channels.
     *
     * @param mixed $notifiable
     *
     * @return array
     */
    public function via($notifiable)
    {
        return [PushNotificationOld::class, DatabaseNotificationOld::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!');
    }

    public function toPush($notifiable)
    {
        $text = Functions::getNotificationSearchText($this->findSessionId, $this->districtName);
        return [
            'type' => config('constants.SEARCH_HOSTEL'),
            '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,
            'id' => $this->findSessionId,
            'renter_id' => !empty($this->findSession) ? $this->findSession->user_id : null
        ];
    }

    /**
     * Get the array representation of the notification.
     *
     * @param mixed $notifiable
     *
     * @return array
     */

    public function toArray($notifiable)
    {
        $text = Functions::getNotificationSearchText($this->findSessionId, $this->districtName);
        return [
            'body' => $text,
            'title' => '🤩Có khách đang tìm nhà này bạn ơi 🤩',
            'id' => $this->findSessionId,
            'image' => $this->user->image,
            'status' => 0,
            'renter_id' => !empty($this->findSession) ? $this->findSession->user_id : null
        ];
    }
}
