<?php

declare(strict_types=1);

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 LoginFromNewDeviceMail extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    public function __construct(
        public readonly string $userName,
        public readonly string $ipAddress,
        public readonly string $loginAt = '',
        public readonly ?string $location = null,
        public readonly ?string $userAgent = null,
    ) {}

    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Yeni Cihazdan Giriş Tespit Edildi — Onoxsoft Panel',
            tags: ['auth', 'security', 'new-device'],
        );
    }

    public function content(): Content
    {
        return new Content(
            view: 'emails.auth.login-from-new-device',
            with: [
                'userName' => $this->userName,
                'ipAddress' => $this->ipAddress,
                'loginAt' => $this->loginAt ?: now()->format('d.m.Y H:i'),
                'location' => $this->location,
                'userAgent' => $this->userAgent,
            ],
        );
    }
}
