<?php

namespace App\Notifications;

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

class AdminNotification extends Notification
{
    use Queueable;

    public $title;
    public $content;
    public $mail_content;
    public $url;
    public $type;
    public $data;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($activity)
    {
        $this->title = $activity->title;
        $this->url = isset($activity->url) ? $activity->url : '/admin';
        $this->content = $activity->content;
        $this->mail_content = $activity->mail_content;
        $this->type = isset($activity->type) ? $activity->type : 'general';
        $this->data = isset($activity->data) ? $activity->data : [];
    }

    /**
     * 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)
    {
        return (new MailMessage)
            ->view('mail.admin', [
                'title' => $this->title, 
                'content' => $this->mail_content,
                'type' => $this->type,
                'data' => $this->data
            ])
            ->subject('🔔 ADMIN ALERT: ' . $this->title);
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            'title' => $this->title,
            'content' => $this->content,
            'url' => $this->url,
            'type' => $this->type,
            'data' => $this->data,
            'is_admin_notification' => true
        ];
    }
} 