<?php

declare(strict_types=1);

use Builder\Core\Foundation\Definition\Field;
use Builder\Core\Foundation\Settings\SettingsSection;

it('make creates a SettingsSection with the given key', function (): void {
    $section = SettingsSection::make('email');

    expect($section)->toBeInstanceOf(SettingsSection::class)
        ->and($section->getKey())->toBe('email');
});

it('label defaults to the key', function (): void {
    expect(SettingsSection::make('email')->getLabel())->toBe('email');
});

it('label() sets the label', function (): void {
    expect(SettingsSection::make('email')->label('Email Settings')->getLabel())->toBe('Email Settings');
});

it('description defaults to null', function (): void {
    expect(SettingsSection::make('email')->getDescription())->toBeNull();
});

it('description() sets the description', function (): void {
    expect(SettingsSection::make('email')->description('Configure email')->getDescription())->toBe('Configure email');
});

it('order defaults to 50', function (): void {
    expect(SettingsSection::make('email')->getOrder())->toBe(50);
});

it('order() sets the order', function (): void {
    expect(SettingsSection::make('email')->order(10)->getOrder())->toBe(10);
});

it('fields defaults to empty array', function (): void {
    expect(SettingsSection::make('email')->getFields())->toBe([]);
});

it('fields() sets fields', function (): void {
    $fields = [Field::text('smtp_host'), Field::text('smtp_port')];
    $section = SettingsSection::make('email')->fields($fields);

    expect($section->getFields())->toHaveCount(2);
});

it('toArray returns correct structure', function (): void {
    $section = SettingsSection::make('email')
        ->label('Email Settings')
        ->description('Configure email')
        ->order(10)
        ->fields([Field::text('smtp_host')]);

    $arr = $section->toArray();

    expect($arr)->toHaveKey('key', 'email')
        ->toHaveKey('label', 'Email Settings')
        ->toHaveKey('description', 'Configure email')
        ->toHaveKey('order', 10)
        ->toHaveKey('fields');
    expect($arr['fields'])->toHaveCount(1);
});
