<?php

declare(strict_types=1);

namespace App\Mail;

use App\Domain\Account\Models\Account;
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 BackupFailedMail extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    public function __construct(
        public readonly Account $account,
        public readonly string $backupDate = '',
        public readonly ?string $errorMessage = null,
    ) {}

    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Yedekleme Başarısız — '.($this->account->primary_domain ?? $this->account->username),
            tags: ['backup', 'failed'],
        );
    }

    public function content(): Content
    {
        return new Content(
            view: 'emails.backup.failed',
            with: [
                'account' => $this->account,
                'backupDate' => $this->backupDate ?: now()->format('d.m.Y H:i'),
                'errorMessage' => $this->errorMessage,
            ],
        );
    }
}
