<?php

use Datalumo\PhpSdk\DataObjects\Integration;

it('creates an integration from array', function () {
    $integration = Integration::fromArray([
        'id' => 'int-123',
        'name' => 'My Chatbot',
        'project' => 'support',
        'type' => 'chatbot',
        'accent_color' => '#ff0000',
        'allowed_domains' => ['example.com'],
        'is_active' => true,
        'settings' => ['welcome_message' => 'Hello!'],
        'collection_ids' => ['col-1', 'col-2'],
        'created_at' => '2026-01-01T00:00:00Z',
        'updated_at' => '2026-01-02T00:00:00Z',
    ]);

    expect($integration)
        ->id->toBe('int-123')
        ->name->toBe('My Chatbot')
        ->project->toBe('support')
        ->type->toBe('chatbot')
        ->accentColor->toBe('#ff0000')
        ->allowedDomains->toBe(['example.com'])
        ->isActive->toBeTrue()
        ->settings->toBe(['welcome_message' => 'Hello!'])
        ->collectionIds->toBe(['col-1', 'col-2']);
});

it('handles missing optional fields', function () {
    $integration = Integration::fromArray([
        'id' => 'int-123',
        'name' => 'My Chatbot',
        'type' => 'chatbot',
        'created_at' => '2026-01-01T00:00:00Z',
        'updated_at' => '2026-01-02T00:00:00Z',
    ]);

    expect($integration)
        ->project->toBeNull()
        ->accentColor->toBe('')
        ->allowedDomains->toBe([])
        ->isActive->toBeTrue()
        ->settings->toBe([])
        ->collectionIds->toBe([]);
});
