<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class ErrorNotification extends Mailable
{
    use Queueable, SerializesModels;

    public $level;
    public $message;
    public $context;
    public $timestamp;

    /**
     * Create a new message instance.
     */
    public function __construct($level, $message, $context = [])
    {
        $this->level = $level;
        $this->message = $message;
        $this->context = $context;
        $this->timestamp = now();
    }

    /**
     * Get the message envelope.
     */
    public function envelope(): Envelope
    {
        $levelLabel = strtoupper($this->level);
        return new Envelope(
            subject: "[{$levelLabel}] Habib Cables ERP - System Error Alert",
        );
    }

    /**
     * Get the message content definition.
     */
    public function content(): Content
    {
        return new Content(
            view: 'emails.error-notification',
            with: [
                'level' => $this->level,
                'message' => $this->message,
                'context' => $this->context,
                'timestamp' => $this->timestamp,
                'environment' => config('app.env'),
                'appName' => config('app.name'),
            ],
        );
    }

    /**
     * Get the attachments for the message.
     *
     * @return array<int, \Illuminate\Mail\Mailables\Attachment>
     */
    public function attachments(): array
    {
        return [];
    }
}
