<?php

namespace Datalumo\PhpSdk\DataObjects;

class Integration
{
    public function __construct(
        public readonly string $id,
        public readonly string $name,
        public readonly ?string $project,
        public readonly string $type,
        public readonly string $accentColor,
        public readonly array $allowedDomains,
        public readonly bool $isActive,
        public readonly array $settings,
        public readonly array $collectionIds,
        public readonly string $createdAt,
        public readonly string $updatedAt,
    ) {}

    public static function fromArray(array $data): self
    {
        return new self(
            id: $data['id'],
            name: $data['name'],
            project: $data['project'] ?? null,
            type: $data['type'],
            accentColor: $data['accent_color'] ?? '',
            allowedDomains: $data['allowed_domains'] ?? [],
            isActive: $data['is_active'] ?? true,
            settings: $data['settings'] ?? [],
            collectionIds: $data['collection_ids'] ?? [],
            createdAt: $data['created_at'],
            updatedAt: $data['updated_at'],
        );
    }
}
