<?php

declare(strict_types=1);

use Builder\Core\Notifications\UserInvitedNotification;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Facades\Schema;

beforeEach(function (): void {
    Schema::create('users', function (Blueprint $table): void {
        $table->id();
        $table->string('name');
        $table->string('email');
        $table->timestamps();
    });
});

it('via returns mail channel', function (): void {
    $notification = new UserInvitedNotification('token123');

    expect($notification->via())->toBe(['mail']);
});

it('toMail returns a MailMessage for a new invite', function (): void {
    $user = new class
    {
        public string $name = 'John';

        public string $email = 'john@example.com';
    };

    $notification = new UserInvitedNotification('abc-token');
    $mail = $notification->toMail($user);

    expect($mail)->toBeInstanceOf(MailMessage::class);
    // actionText is set for invite (not reset)
    expect($mail->actionText)->not->toBeEmpty();
    expect($mail->actionUrl)->toContain('abc-token');
});

it('toMail returns a different MailMessage when isReset is true', function (): void {
    $user = new class
    {
        public string $name = 'Jane';

        public string $email = 'jane@example.com';
    };

    $notification = new UserInvitedNotification('reset-token', isReset: true);
    $mail = $notification->toMail($user);

    expect($mail)->toBeInstanceOf(MailMessage::class);
    expect($mail->actionUrl)->toContain('reset-token');
});
