<?php

namespace App\Mail\Admin;

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

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

    public function envelope(): Envelope
    {
        return new Envelope(subject: $this->adminSubject('Subscription canceled'));
    }

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

        return new Content(
            markdown: 'mail.admin.subscription-canceled',
            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',
                'providerKey' => $this->subscription->provider_key,
                'canceledAt' => $this->subscription->canceled_at,
                'periodEndsAt' => $this->subscription->current_period_ends_at,
                'cancelsAtPeriodEnd' => (bool) $this->subscription->cancels_at_period_end,
                'isTest' => (bool) $this->subscription->is_test,
            ]),
        );
    }
}
