<?php

namespace App\Mail;

use App\Mail\Concerns\UsesTenantBranding;
use App\Models\Central\Company;
use App\Models\Tenant\Payment;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class PaymentReceivedMail extends Mailable
{
    use Queueable, SerializesModels, UsesTenantBranding;

    public function __construct(public Payment $payment, Company $company)
    {
        $this->company = $company;
    }

    public function envelope(): Envelope
    {
        return new Envelope(
            subject: "[{$this->company->name}] Confirmare plată — " . number_format((float) $this->payment->amount, 2, '.', ' ') . ' ' . ($this->company->settings['currency'] ?? 'MDL'),
            from: new \Illuminate\Mail\Mailables\Address(
                config('mail.from.address'),
                $this->company->display_name ?? $this->company->name,
            ),
        );
    }

    public function content(): Content
    {
        return new Content(
            view: 'emails.payment-received',
            with: array_merge($this->buildBrandingContext(), [
                'payment' => $this->payment,
                'client' => $this->payment->client,
                'workOrder' => $this->payment->workOrder,
                'currency' => $this->company->settings['currency'] ?? 'MDL',
            ]),
        );
    }
}
