<?php

declare(strict_types=1);

use Builder\Core\Foundation\Definition\Field;

it('translatable defaults to false', function (): void {
    expect(Field::make('title')->isTranslatable())->toBeFalse();
});

it('translatable sets to true', function (): void {
    expect(Field::make('title')->translatable()->isTranslatable())->toBeTrue();
});

it('translatable accepts explicit true', function (): void {
    expect(Field::make('title')->translatable(true)->isTranslatable())->toBeTrue();
});

it('translatable accepts explicit false', function (): void {
    expect(Field::make('title')->translatable(false)->isTranslatable())->toBeFalse();
});

it('translatable returns self for chaining', function (): void {
    $field = Field::make('title');
    $result = $field->translatable();

    expect($result)->toBe($field);
});

it('generateFrom defaults to null', function (): void {
    expect(Field::make('slug')->getGenerateFrom())->toBeNull();
});

it('generateFrom sets source field', function (): void {
    expect(Field::make('slug')->generateFrom('title')->getGenerateFrom())->toBe('title');
});

it('generateFrom returns self for chaining', function (): void {
    $field = Field::make('slug');
    $result = $field->generateFrom('title');

    expect($result)->toBe($field);
});

it('toArray includes translatable key as false by default', function (): void {
    $array = Field::make('title')->toArray();

    expect($array)->toHaveKey('translatable')
        ->and($array['translatable'])->toBeFalse();
});

it('toArray includes translatable key as true when set', function (): void {
    $array = Field::make('title')->translatable()->toArray();

    expect($array['translatable'])->toBeTrue();
});

it('toArray includes generateFrom as null by default', function (): void {
    $array = Field::make('slug')->toArray();

    expect($array)->toHaveKey('generateFrom')
        ->and($array['generateFrom'])->toBeNull();
});

it('toArray includes generateFrom value when set', function (): void {
    $array = Field::make('slug')->generateFrom('title')->toArray();

    expect($array['generateFrom'])->toBe('title');
});
