<?php

declare(strict_types=1);

use App\Framework\MagicLinks\Commands\GenerateMagicLinkCommand;
use App\Framework\MagicLinks\TokenAction;
use App\Framework\MagicLinks\TokenConfig;
use App\Framework\MagicLinks\ValueObjects\MagicLinkPayload;

describe('GenerateMagicLinkCommand', function () {
    it('creates command with required parameters', function () {
        $action = new TokenAction('email_verification');
        $payload = MagicLinkPayload::fromArray(['email' => 'test@example.com']);

        $command = new GenerateMagicLinkCommand(
            action: $action,
            payload: $payload
        );

        expect($command->action)->toBe($action);
        expect($command->payload)->toBe($payload);
        expect($command->config)->toBeNull();
        expect($command->baseUrl)->toBeNull();
    });

    it('creates command with all parameters', function () {
        $action = new TokenAction('email_verification');
        $payload = MagicLinkPayload::fromArray(['email' => 'test@example.com']);
        $config = new TokenConfig(expiryHours: 24);

        $command = new GenerateMagicLinkCommand(
            action: $action,
            payload: $payload,
            config: $config,
            baseUrl: 'https://example.com',
            createdByIp: '127.0.0.1',
            userAgent: 'Test Agent'
        );

        expect($command->action)->toBe($action);
        expect($command->payload)->toBe($payload);
        expect($command->config)->toBe($config);
        expect($command->baseUrl)->toBe('https://example.com');
        expect($command->createdByIp)->toBe('127.0.0.1');
        expect($command->userAgent)->toBe('Test Agent');
    });

    it('payload is MagicLinkPayload value object', function () {
        $action = new TokenAction('test');
        $payload = MagicLinkPayload::fromArray(['test' => 'value']);

        $command = new GenerateMagicLinkCommand(
            action: $action,
            payload: $payload
        );

        expect($command->payload)->toBeInstanceOf(MagicLinkPayload::class);
        expect($command->payload->toArray())->toBe(['test' => 'value']);
    });
});
