<?php

declare(strict_types=1);

use Builder\Core\Foundation\Definition\JsModule;

it('make creates a JsModule instance', function (): void {
    expect(JsModule::make())->toBeInstanceOf(JsModule::class);
});

it('setEntry sets the entry and getEntry returns it', function (): void {
    $module = JsModule::make()->setEntry('resources/js/custom.ts');

    expect($module->getEntry())->toBe('resources/js/custom.ts');
});

it('entry defaults to resources/js/module.ts', function (): void {
    expect(JsModule::make()->getEntry())->toBe('resources/js/module.ts');
});

it('setPublicPath sets the publicPath and getPublicPath returns it', function (): void {
    $module = JsModule::make()->setPublicPath('/var/www/public');

    expect($module->getPublicPath())->toBe('/var/www/public');
});

it('getPublicPath returns null when not set', function (): void {
    expect(JsModule::make()->getPublicPath())->toBeNull();
});

it('toArray returns key, entry, and label', function (): void {
    $module = JsModule::make()
        ->setKey('my-module')
        ->setEntry('resources/js/my-module.ts')
        ->setLabel('My JsModule');

    $arr = $module->toArray();

    expect($arr)->toHaveKey('key', 'my-module')
        ->toHaveKey('entry', 'resources/js/my-module.ts')
        ->toHaveKey('label', 'My JsModule');
});

it('toArray label is null when not set', function (): void {
    $module = JsModule::make()->setKey('test');

    expect($module->toArray()['label'])->toBeNull();
});

it('setVersion and getVersion round-trip correctly', function (): void {
    $module = JsModule::make()->setVersion('1.2.3');

    expect($module->getVersion())->toBe('1.2.3');
});

it('getVersion returns null when not set', function (): void {
    expect(JsModule::make()->getVersion())->toBeNull();
});

it('setAuthor and getAuthor round-trip correctly', function (): void {
    $module = JsModule::make()->setAuthor('Spatie');

    expect($module->getAuthor())->toBe('Spatie');
});

it('getAuthor returns null when not set', function (): void {
    expect(JsModule::make()->getAuthor())->toBeNull();
});

it('setAuthorUrl and getAuthorUrl round-trip correctly', function (): void {
    $module = JsModule::make()->setAuthorUrl('https://spatie.be');

    expect($module->getAuthorUrl())->toBe('https://spatie.be');
});

it('getAuthorUrl returns null when not set', function (): void {
    expect(JsModule::make()->getAuthorUrl())->toBeNull();
});

it('toArray includes version, author, and author_url', function (): void {
    $module = JsModule::make()
        ->setKey('my-module')
        ->setVersion('2.0.0')
        ->setAuthor('Spatie')
        ->setAuthorUrl('https://spatie.be');

    $arr = $module->toArray();

    expect($arr)->toHaveKey('version', '2.0.0')
        ->toHaveKey('author', 'Spatie')
        ->toHaveKey('author_url', 'https://spatie.be');
});
