<?php

namespace App\Mail;

use App\Models\WithdrawalRequest;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class AdminWithdrawalRequestedMail extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(public WithdrawalRequest $withdrawalRequest) {}

    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Nuevo retiro solicitado',
        );
    }

    public function content(): Content
    {
        $investor = $this->withdrawalRequest->requester;

        return new Content(
            markdown: 'mail.admin.withdrawal-requested',
            with: [
                'investorName' => $investor?->name ?? '—',
                'investorEmail' => $investor?->email ?? '—',
                'amount' => number_format((float) $this->withdrawalRequest->amount, 2, '.', ''),
                'feeTotal' => number_format((float) $this->withdrawalRequest->fee_total, 2, '.', ''),
                'netAmount' => number_format((float) $this->withdrawalRequest->net_amount, 2, '.', ''),
                'destinationNetwork' => $this->withdrawalRequest->destination_currency_network ?: '—',
                'destinationAddress' => $this->withdrawalRequest->destination_address ?: '—',
                'destinationLabel' => $this->withdrawalRequest->destination_label ?: '—',
                'requesterNote' => filled($this->withdrawalRequest->requester_note)
                    ? $this->withdrawalRequest->requester_note
                    : null,
                'actionUrl' => route('admin.withdrawals.requests.index', absolute: true),
            ],
        );
    }
}
