<?php

namespace App\Modules\Exports\Notifications;

use App\Modules\Exports\Models\Export;
use App\Support\NotificationCategory;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;

class ExportFinishedNotification extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct(
        public readonly Export $export,
        public readonly bool $success,
    ) {}

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

    /**
     * @return array<string, mixed>
     */
    public function toArray(object $notifiable): array
    {
        $key = $this->success ? 'exports.notifications.done_body' : 'exports.notifications.failed_body';

        return [
            'category' => NotificationCategory::SYSTEM,
            'tenant_id' => (int) $this->export->tenant_id,
            'type' => $this->success ? 'export_completed' : 'export_failed',
            'export_id' => $this->export->id,
            'title' => $this->success
                ? __('exports.notifications.done_title')
                : __('exports.notifications.failed_title'),
            'body' => __($key, ['id' => $this->export->id]),
        ];
    }
}
