<?php

namespace App\Mail;

use App\Mail\Concerns\RidesALane;
use App\Mail\Concerns\SendsFromMailbox;
use App\Models\User;
use App\Services\Mail\MailCatalogue;
use App\Services\Mail\MailPurpose;
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;

/**
 * "Your account will be removed in a fortnight, and here is how to keep it."
 *
 * Sent once, a fortnight before an account that has never had a package is
 * deleted for good (App\Console\Commands\PruneDormantAccounts). Not a marketing
 * mail and not a nudge to buy something: it says what will happen, when, and that
 * signing in is enough to stop it.
 *
 * From the SYSTEM mailbox — this is about the login, not about money and not
 * about a running service.
 */
class DormantAccountWarningMail extends Mailable implements ShouldQueue
{
    use Queueable, RidesALane, SendsFromMailbox, SerializesModels;

    public function __construct(public User $user, public int $days)
    {
        $this->mailer(MailCatalogue::mailer('dormant-warning'));
    }

    public function envelope(): Envelope
    {
        return $this->mailboxEnvelope(MailPurpose::SYSTEM, __('dormant_mail.subject'), 'dormant-warning');
    }

    public function content(): Content
    {
        return new Content(view: 'mail.dormant-warning', with: [
            'name' => (string) $this->user->name,
            'days' => $this->days,
            'loginUrl' => route('login'),
        ]);
    }
}
