<?php

namespace App\Notifications;

use App\Models\OperationRun;
use App\Models\Tenant;
use App\Support\OperationCatalog;
use App\Support\OperationRunLinks;
use Filament\Notifications\Notification as FilamentNotification;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;

class OperationRunQueued extends Notification
{
    use Queueable;

    public function __construct(
        public OperationRun $run
    ) {}

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

    /**
     * @return array<string, mixed>
     */
    public function toDatabase(object $notifiable): array
    {
        $tenant = $this->run->tenant;

        $operationLabel = OperationCatalog::label((string) $this->run->type);

        return FilamentNotification::make()
            ->title("{$operationLabel} queued")
            ->body('Queued. Monitor progress in Monitoring → Operations.')
            ->warning()
            ->actions([
                \Filament\Actions\Action::make('view_run')
                    ->label('View run')
                    ->url($tenant instanceof Tenant ? OperationRunLinks::view($this->run, $tenant) : null),
            ])
            ->getDatabaseMessage();
    }
}
