<?php

declare(strict_types=1);

namespace App\Framework\Deployment\Docker\ValueObjects;

/**
 * Docker Compose Project Name
 *
 * Represents a compose project identifier for multi-container deployments.
 */
final readonly class ComposeProject
{
    public function __construct(
        public string $name
    ) {
        if (empty($name)) {
            throw new \InvalidArgumentException('Compose project name cannot be empty');
        }

        // Validate project name format (alphanumeric, dash, underscore)
        if (!preg_match('/^[a-zA-Z0-9_-]+$/', $name)) {
            throw new \InvalidArgumentException(
                'Compose project name must contain only alphanumeric characters, dashes, and underscores'
            );
        }
    }

    public static function fromString(string $name): self
    {
        return new self($name);
    }

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

    public function __toString(): string
    {
        return $this->name;
    }
}
