<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;

/**
 * In-app notification raised to a MEMBER when an owner/admin changes their
 * workspace role (Team Workspaces). Database channel only — lands in the
 * `notifications` table + AppNav bell. The matching email is the queued
 * {@see \App\Mail\Workspace\WorkspaceRoleChangedMail}.
 *
 * NOT `ShouldQueue` (mirrors {@see ProjectShared}): a single synchronous in-app
 * row, scalar args. `url` is null — a role change is informational, not a
 * click-through (the member's capabilities just shifted in place).
 *
 * `data` shape: { title, body, url:null }
 */
class WorkspaceRoleChanged extends Notification
{
    use Queueable;

    public function __construct(
        public string $workspaceName,
        public string $role, // 'admin' | 'editor' | 'viewer'
        public string $actorName,
    ) {}

    /**
     * @return array<int, string>
     */
    public function via(object $notifiable): array
    {
        return ['database'];
    }

    /**
     * @return array{title: string, body: string, url: null}
     */
    public function toArray(object $notifiable): array
    {
        $actor = $this->actorName !== '' ? $this->actorName : 'An admin';
        $role = ucfirst($this->role);

        return [
            'title' => 'Your workspace role changed',
            'body' => "{$actor} changed your role in \"{$this->workspaceName}\" to {$role}",
            'url' => null,
            'workspace' => $this->workspaceName,
            'category' => 'role',
        ];
    }
}
