<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use App\Models\Post;

class PostStatusNotification extends Notification
{
    use Queueable;

    protected $post;

    public function __construct(Post $post)
    {
        $this->post = $post;
    }

    public function via(object $notifiable): array
    {
        return ['database'];
    }

    public function toArray(object $notifiable): array
    {
        $status = ucfirst($this->post->status);
        $message = "Your post \"{$this->post->title}\" has been {$status}.";

        return[
            'type' => 'status',
            'status' => $this->post->status, // 'published' or 'rejected'
            'message' => $message,
            
            'url' => $this->post->status === 'published' 
                ? $this->post->route_url 
                : route('my-posts.index'),
                
            'created_at' => now(),
        ];
    }
}