<?php

declare(strict_types=1);

namespace App\Application\LiveComponents\ValueObjects;

/**
 * DataSource - Identifies which data to load for a component
 *
 * Examples:
 * - 'demo' - Demo/fake data for development
 * - 'sales' - Sales metrics from database
 * - 'traffic' - Traffic analytics
 * - 'users' - User statistics
 */
final readonly class DataSource
{
    public function __construct(
        public string $value,
        public array $config = []
    ) {
        if (empty($value)) {
            throw new \InvalidArgumentException('DataSource value cannot be empty');
        }
    }

    public static function demo(): self
    {
        return new self('demo');
    }

    public static function fromString(string $value, array $config = []): self
    {
        return new self($value, $config);
    }

    public function isDemo(): bool
    {
        return $this->value === 'demo';
    }

    public function equals(self $other): bool
    {
        return $this->value === $other->value;
    }

    public function toArray(): array
    {
        return [
            'value' => $this->value,
            'config' => $this->config,
        ];
    }
}
