<?php
declare(strict_types=1);

namespace FreshCloud\Mail\Tests\ImapRequests;

use FreshCloud\Mail\ImapRequests\ImapCommand;
use FreshCloud\Mail\ImapRequests\ImapRequestBuilder;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[CoversClass(ImapRequestBuilder::class)]
final class ImapRequestBuilderTest extends TestCase
{
    public function testBuildCommandWithoutMethods(): void
    {
        $builder = new ImapRequestBuilder();
        $command = $builder->build();
        $this->assertInstanceOf(ImapCommand::class, $command);
        $this->assertSame('NOOP', $command->name);
    }

    public function testBuildFetchCommand(): void
    {
        $command = (new ImapRequestBuilder())->fetch()->build();
        $this->assertSame('FETCH', $command->name);
    }

    public function testBuildWithCustomTag(): void
    {
        $command = (new ImapRequestBuilder())->tag(123)->command('SEARCH', ['ALL'])->build();
        $this->assertSame('SEARCH', $command->name);
        $this->assertEquals(['ALL'], $command->args);
    }

    public function testChaining(): void
    {
        $builder = new ImapRequestBuilder();
        $this->assertSame($builder, $builder->tag(1));
        $this->assertSame($builder, $builder->command('TEST', ['arg1', 'arg2']));
    }
}