<?php

namespace Tests\Feature;

use App\Models\PackagePurchase;
use App\Models\Tenant;
use App\Notifications\Customer\RefundReceipt;
use App\Notifications\InactiveTenantDeletionWarning;
use App\Notifications\Ops\PurchaseCreated;
use App\Notifications\UploadPipelineFailed;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Carbon;
use Tests\TestCase;

class BrandedNotificationEmailsTest extends TestCase
{
    use RefreshDatabase;

    public function test_upload_pipeline_failed_uses_branded_view(): void
    {
        $notification = new UploadPipelineFailed([
            'job' => 'UploadJob',
            'queue' => 'uploads',
            'event_id' => 123,
            'photo_id' => 456,
            'exception' => 'ExampleException',
        ]);

        $mailMessage = $notification->toMail((object) []);

        $this->assertInstanceOf(MailMessage::class, $mailMessage);
        $this->assertSame('emails.notifications.basic', $mailMessage->view);
        $this->assertArrayHasKey('lines', $mailMessage->viewData);
    }

    public function test_inactive_tenant_deletion_warning_uses_branded_view(): void
    {
        $tenant = Tenant::factory()->create([
            'name' => 'Demo Tenant',
        ]);

        $notification = new InactiveTenantDeletionWarning($tenant, Carbon::now()->addDays(10));
        $mailMessage = $notification->toMail((object) []);

        $this->assertInstanceOf(MailMessage::class, $mailMessage);
        $this->assertSame('emails.notifications.basic', $mailMessage->view);
        $this->assertArrayHasKey('cta', $mailMessage->viewData);
    }

    public function test_refund_receipt_uses_branded_view(): void
    {
        $purchase = PackagePurchase::factory()->create();
        $notification = new RefundReceipt($purchase);
        $mailMessage = $notification->toMail((object) []);

        $this->assertInstanceOf(MailMessage::class, $mailMessage);
        $this->assertSame('emails.notifications.basic', $mailMessage->view);
        $this->assertArrayHasKey('footer', $mailMessage->viewData);
    }

    public function test_ops_purchase_created_uses_branded_view(): void
    {
        $purchase = PackagePurchase::factory()->create();
        $notification = new PurchaseCreated($purchase);
        $mailMessage = $notification->toMail((object) []);

        $this->assertInstanceOf(MailMessage::class, $mailMessage);
        $this->assertSame('emails.notifications.basic', $mailMessage->view);
    }
}
