<?php

namespace App\Mail\Admin;

use App\Models\Subscription;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;

class NewSubscriptionAdmin extends BaseAdminNotification
{
    public function __construct(public Subscription $subscription) {}

    public function envelope(): Envelope
    {
        return new Envelope(subject: $this->adminSubject('New paid subscription'));
    }

    public function content(): Content
    {
        $user = $this->subscription->user;

        return new Content(
            markdown: 'mail.admin.new-subscription',
            with: array_merge($this->commonData(), [
                'userName' => $user?->name ?: $this->subscription->user_email_snapshot ?: '(unknown user)',
                'userEmail' => $user?->email ?: $this->subscription->user_email_snapshot ?: '(no email)',
                'planName' => $this->subscription->plan?->name ?: 'unknown plan',
                'period' => $this->subscription->period,
                'providerKey' => $this->subscription->provider_key,
                'subscription' => $this->subscription,
                'isTest' => (bool) $this->subscription->is_test,
            ]),
        );
    }
}
